Spritekit中的新场景未显示任何内容?

时间:2018-08-25 18:54:41

标签: ios swift sprite-kit

我有GameScene,在触摸的节点上,它进入了一个名为PlayScene的新场景。这已成功完成,但是我添加到PlayScene的所有子节点均未显示。但是,我可以在新场景中更改背景颜色。

这是我在GameScene中拥有的:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let location = touches.first?.location(in: self)
    let nodeTouched = atPoint(location!)

    if nodeTouched.name == "playButton" {
        print("Play Button Pressed")
        let playScreenTransition = SKTransition.fade(with: UIColor(red: 35/255, green: 161/255, blue: 234/255, alpha: 1.0), duration: 0.5)

        self.view?.presentScene(PlayScene(size: screenSize), transition: playScreenTransition)
        vibrateGenLight.impactOccurred()
    }
}

在PlayScene中:

class PlayScene: SKScene{

    //UI Elements
    let background = SKSpriteNode(imageNamed: "Background")
    let stickyBlock = SKSpriteNode(imageNamed: "StickyBlock")

    override func didMove(to view: SKView) {
        print("In PlayScene")
        let xy = 0.5;
        anchorPoint = CGPoint(x: xy, y: xy)

        self.addChild(background)

        self.addChild(stickyBlock)
    }
}

在GameViewController中:

class GameViewController: UIViewController {

    override func viewDidLoad() {
        let scene = GameScene(size: view.frame.size)
        let skView = view as! SKView
        skView.presentScene(scene)
    }
}

我这里缺少什么吗?

1 个答案:

答案 0 :(得分:0)

stickyBlock.anchorPoint = CGPoint(x:xy,y:xy)