2016-07-01 11 views
1

그래서 게임을 만들고 영웅을위한 물리학 경계를 작성하려고합니다. 그래서 발사 롤에 바닥에 떨어지지 않습니다. 내 장면을 구현하고 내 "desertForeground"에서 알파 마스크 텍스처 물리학 바디를 만들려고하는데 아무런 오류가 발생하지 않지만 충돌이 계속되고이 오류가 발생하고 디버깅이 나에게 많이 알려주지 않는다면 기본적으로 무효화 된 명령을 말하지만 왜 잘못되었는지는 알려주지 않습니다. Error screenshot 아무도 나를 도울 수 있습니까? 난 당신이 desertForegroundTexture을 채우는 방법을 문제가 신속알파 마스크/텍스처 피직스 바디 실행시 치명적인 오류 - 신속한

import SpriteKit 

enum BodyType:UInt32 { 

case hero = 01 

case bullet1 = 010 

case enemy1 = 0100 
case enemy2 = 01000 
case enemy3 = 010000 

case desertForegroundCase = 02 
} 
class GameScene: SKScene, SKPhysicsContactDelegate { 

    let desertBackground = SKSpriteNode (imageNamed: "RZ- 
DesertBackground.png") 
let desertForeground = SKSpriteNode (imageNamed: "RZ- 
DesertForeground.png") 
let desertgully = SKSpriteNode (imageNamed: "RZ-DesertGully.png") 

    override func didMoveToView(view: SKView) { 
     CreateScene() 
} 
    func CreateScene(){ 

    desertForeground.position = CGPoint(x: 570 , y: 102) 
    desertForeground.size = CGSize (width: 1136, height: 200) 
    desertForeground.zPosition = 1 

    let desertForegroundTexture = SKTexture() 
    let desertForegroundBody = SKPhysicsBody(texture: 
    desertForegroundTexture, size: CGSize(width: 1136, height: 200)) 

    desertForeground.texture = desertForegroundTexture 

    desertForegroundBody.dynamic = true 
    desertForegroundBody.affectedByGravity = false 
    desertForegroundBody.allowsRotation = false 
    desertForegroundBody.categoryBitMask = 
        BodyType.desertForegroundCase.rawValue 
    desertForegroundBody.contactTestBitMask = BodyType.enemy1.rawValue 
    | BodyType.enemy2.rawValue | BodyType.enemy3.rawValue | 
     BodyType.soldierL.rawValue | BodyType.soldierT.rawValue 

    desertForeground.physicsBody = desertForegroundBody 
} 
} 

답변

1

에서 물리학 몸을 코딩에 아주 새로운 해요.

당신이 빈 질감에서 physicBody을 만들 때 온이

let desertForegroundTexture = SKTexture(imageNamed: "YOUR_IMAGE_NAME") 
0

문제와이

let desertForegroundTexture = SKTexture() 

교체 : 사실

/** 
    Creates a body from the alpha values in the supplied texture. 
    @param texture the texture to be interpreted 
    @param size of the generated physics body 
    */ 
    @available(iOS 8.0, *) 
    public /*not inherited*/ init(texture: SKTexture, size: CGSize) 

예를 들어이 들어, 이런 종류의 일은 일어나지 않습니다. 다음과 같이 SKSpriteNode을 만들려고한다면 :

let desertForegroundTexture = SKTexture() 
desertForeground = SKSpriteNode(texture: desertForegroundTexture, size:CGSize(width: 1136, height: 200))