在swift中创建精灵套件游戏.将角色添加到场景中



我正在创建一个游戏,我已经设置了背景。现在,当我输入代码将角色添加到场景中时,它不会出现。这是我用来尝试让角色出现在屏幕上的代码。显然我的角色出现在幕后。有没有其他方法可以让角色出现在背景前?

 func createPlayer() -> SKNode {
    let playerNode = SKNode()

        playerNode.position = CGPoint(x: self.size.width / 2, y: 80.0)
        let sprite = SKSpriteNode(imageNamed: "Pig")
        playerNode.addChild(sprite) return playerNode }

为了使字符出现在背景图像的前面,您需要使用zposition:

//You need to choose a high zposition number to make sure it shows up in front.
    playerNode.zPosition = 1
// you should set the background images z position using the same method to something below 1

我还建议使用这个来将你的角色添加到场景中:

self.addChild(playerNode)

最新更新