Zombie Conga - Pg 61. Code error / zombie won't move!

Hello,

I am working on the code at the bottom of page 61 where we are trying to get the zombie to move along the x axis. One error it gives me is that “override” should not be a part of the code given in the section:
"
override func update(_ currentTime: TimeInterval) {
zombie.position = CGPoint(x: zombie.position.x + 8,
}
"

I remove the “override” and it removes the error. I build and run the simulation, but the zombie still does not move. Any ideas on what is going wrong? My code is pasted below. Thanks in advance!

import SpriteKit

class GameScene: SKScene {

// Challenge 1: Create the zombie and position it at (400, 400)
let zombie = SKSpriteNode(imageNamed: "zombie1")

override func didMove(to view: SKView) {
    backgroundColor = SKColor.black
    let background = SKSpriteNode(imageNamed: "background1")
    //background.position = CGPoint(x: size.width/2, y: size.height/2)
    background.anchorPoint = CGPoint.zero
    background.position = CGPoint.zero
    background.zPosition = -1
    addChild(background)
    let mySize = background.size
    print("Size: \(mySize)")
    zombie.position = CGPoint(x: 400, y: 400)
    addChild(zombie)
    
    func update(_ currentTime: TimeInterval) {
        zombie.position = CGPoint(x: zombie.position.x + 8,
                                  y: zombie.position.y)
        
}

}
}

@steven_simpson

One thing that stands out is that you have defined update(_:) as being part of didMove(to:).

You should have a } after addChild(zombie) to close the didMove(to:) method.

The indentation is a clue - func update(_:) should be at the same level of indentation as override func didMove(to:)

This topic was automatically closed after 166 days. New replies are no longer allowed.