SpriteNode不可见

时间:2016-03-28 21:32:47

标签: ios swift sprite-kit

我正在尝试使用以下Methode创建User SpriteNode。纹理是Kladde,Image也不是空的。

func spawnPlayer() {
    if didFirstTap == true && isGameOver == false {
        let collisionMask = CollisionCategory.Surrounding.rawValue | CollisionCategory.Platform.rawValue
        let x = self.frame.size.width / 4
        let y = CGRectGetMidY(self.frame)
        let node = SKNode()
        node.position = CGPointMake(frame.size.width + playerTexture!.size().width, 0)
        playerNode = SKSpriteNode(texture: playerTexture)
        playerNode!.setScale(1.0)
        playerNode!.position = CGPointMake(x, y)
        playerNode!.speed = 1.0
        playerNode!.zRotation = 0.0
        playerNode!.physicsBody = SKPhysicsBody(circleOfRadius: playerNode!.size.height / 2)
        playerNode!.physicsBody?.dynamic = true
        playerNode!.physicsBody?.allowsRotation = false
        playerNode!.physicsBody?.categoryBitMask = CollisionCategory.Player.rawValue
        playerNode!.physicsBody?.contactTestBitMask = collisionMask
        playerNode!.physicsBody?.collisionBitMask = collisionMask
        playerNode!.physicsBody!.velocity = CGVectorMake( 0, 0 )
        node.addChild(playerNode!)
        addChild(node)
    }
}

我希望有人知道,为什么我的Node不可见?

1 个答案:

答案 0 :(得分:1)

查看节点产生的位置:

node.position = CGPointMake(frame.size.width + playerTexture!.size().width, 0)

然后在此基础上将玩家移动到节点的位置

let x = self.frame.size.width / 4
let y = CGRectGetMidY(self.frame)
playerNode!.position = CGPointMake(x, y)

这个可怜的家伙远离屏幕空间。