如何在其他类而不是GameScene中添加节点?

时间:2018-10-16 19:48:41

标签: swift xcode

我正在尝试使用以下代码片段在另一个类中创建一个节点:

func animateDeck() {

        let chip = SKSpriteNode(imageNamed: "ChipWindSnake")
        chip.position = CGPoint(x: 50, y: 70)
        chip.zPosition = 1
        chip.setScale(1)
        self.addChild(chip)

}

显示此错误:

Cannot convert value of type 'SKSpriteNode' to expected argument type 'UIViewController'

我试图用GameScene代替self:

GameScene.addChild(chip)

发生以下错误:

'SKSpriteNode' is not convertible to 'GameScene'

我尝试的另一个变体是我在GameScene中编写了代码,并试图在另一个类中访问它。不幸的是,这也不起作用。

希望您能帮助我找到解决方案。

谢谢。

0 个答案:

没有答案