嗨,大家好我试图将这个动画添加到我的游戏状态我收到此错误
覆盖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)
}
答案 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