0

Hi guys am trying to add this animation to my game state am getting this error

override 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 Answers2

0

As the error describes, the GKState class doesn't have any member functions called childNodeWithName.

bfs
  • 81
  • 3
0

You forget to reference GameScene file

Replace:

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

With:

let scene = GameScene(fileNamed:"GameScene") //Or everywhere is your sprite
Ninja_Run = scene.childNodeWithName("Ninja_Run") as! SKSpriteNode
Simone Pistecchia
  • 2,746
  • 3
  • 18
  • 30