我正在尝试使用以下方法创建用户Sprite节点。纹理为Kladde,图像也不为空。

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不可见?

最佳答案

查看节点产生的位置:

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)


这个可怜的家伙不在屏幕空间之内。

关于ios - SpriteNode不可见,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36271572/

10-09 10:21