在SpriteKit Error中向状态机添加动画

时间:2016-06-01 18:37:15

标签: sprite-kit gameplay-kit

嗨,大家好我试图将这个动画添加到我的游戏状态我收到此错误

覆盖func didEnterWithPreviousState(previousState:GKState?){

    Ninja_Run = self.childNodeWithName("Ninja_Run") as! SKSpriteNode //ERROR HERE:RunningState' has no member 'childNodeWithName'
    var frames: [SKTexture] = []
    for i in 0 ..< 9 {
        let tex:SKTexture = SKTexture(imageNamed: "Run__00\(i).png")
        frames.append(tex)
    }
    Ninja_Run!.runAction(SKAction.repeatActionForever(SKAction.animateWithTextures(frames, timePerFrame: 0.055)))
    Ninja_Run!.size = CGSize(width: 150, height: 150)

}

2 个答案:

答案 0 :(得分:0)

正如错误所描述的那样,GKState类没有任何名为childNodeWithName的成员函数。

答案 1 :(得分:0)

您忘记参考 GameScene 文件

<强>替换

Ninja_Run = self.childNodeWithName("Ninja_Run") as! SKSpriteNode

。通过

let scene = GameScene(fileNamed:"GameScene") //Or everywhere is your sprite
Ninja_Run = scene.childNodeWithName("Ninja_Run") as! SKSpriteNode