Fixex movement per frame

I’m reading the book and following it step by steps. I typed this code from pg 60.

override func update(currentTime: NSTimeInterval) {
zombie.positon = CGPoint(x: zombie.position.x + 8, y: zombie.position.y)

After typing this code it gives me an error stating " use of unresolved identifier “zombie”

I tried to backtracking to see if I missed anything in my reading but I cant seem to find anything and I after several hours, I cant find a solution to the problem. Any suggestions?

You’re accessing a variable named “zombie” - my first step would be to look at the top of the module you are editing and see if you have it defined at class scope. I don’t think you do, and you probably should.

I’m sorry I don’t understand what you mean, this is what i have so far…

import SpriteKit

class GameScene: SKScene {

override func didMoveToView(view: SKView) {
    backgroundColor = SKColor.blackColor()
    let background = SKSpriteNode(imageNamed: "background1")
    background.position = CGPoint (x: size.width/2, y: size.height/2)
    background.anchorPoint = CGPoint (x: 0.5, y: 0.5) // default
    //background.zRotation = CGFloat (M_PI) / 8
    background.zPosition = -1
    let mySize = background.size
    print("Size: \(mySize)")
    let zombie = SKSpriteNode(imageNamed: "zombie1")
    zombie.position = CGPoint (x: 400, y: 400)
override func update(currentTime: NSTimeInterval) {
    zombie.positon = CGPoint(x: zombie.position.x + 8, y: zombie.position.y)

OK, your issue is that you have zombie defined in the scope of the function didMoveToView - then you try to access it in update(). In update it just doesn’t exist. If you have only one zombie then move the definition up to class scope - that means within the class definition but not within a function.

But - since you’re working with SKSpriteNode objects and you are adding them to the scene (your class inherits from SKScene, which inherits from SKNode) - you can get the zombie back from the scene. If you set the name of the zombie object when you add it you can then use childNodeWithName to get it back.

This is almost certainly what you want to do because you are updating the position of an existing zombie. So in didMoveToView, add an identifier, like = "zombie1"

then later use


to get it back. Once you have the valid zombie object you can update its position. Note that you don’t want to use an identifier for a zombie more than once - they need to be unique!

Thank you!! You gave me some tools for me to do some thinking and with your help I figured it out. I almost have no EX in coding and this is a fun hobby to have. Thank you.

I have the same problem here but I dot understand how to solve it …What did you do to fix it ?

alright problem solved …for anybody having this problem make sure your are putting the code after the curly braces followed after adding the child nodes and type each word one by one to then select each line of code such as zombie.position … etc …DO NOT JUST WRITE THE CODE YOURSELF YOU HAVE TO SELECT IT … THIS SOLVED THE PROBLEM FOR ME!!!