Zombie Conga , Moving the zombie

I bought 2D iOS & tvOs Games by tutorials a long time ago, and now I am reading it. I am disappointed there won’t be any new updates!
So, anyway I had the same problem that the zombie won’t move across the screen, it just stays in one spot.

I looked at the last solution that someone had the same problem and had to put the override fun update after the override func didMove curly brace }, but then I got an error about the zombie and figured it out that you have to make the variable let zombie = SKSpriteNode(imageNamed: “zombie1”) a global variable.
Here is the solution:
import SpriteKit
import GameplayKit

class GameScene: SKScene {

**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(x: 0.5, y: 0.5)
    background.position = CGPoint(x: size.width / 2, y: size.height / 2)
   // background.zRotation = CGFloat.pi / 8
    background.zPosition = -1
    addChild(background)
    
    let mySize = background.size
    print("Size: \(mySize)")
    
    
    zombie.position = CGPoint(x: 400, y: 400)
    //zombie.setScale(2)
    addChild(zombie)
   
}
    
   **override func update(_ currentTime: TimeInterval) { zombie.position = CGPoint(x: zombie.position.x + 8,**

** y: zombie.position.y)**
}
}

I Just figured out how to edit my post! Anyway the ** symbols on the top and bottom of the code were supposed to be BOLD. But I guess the Bold function doesn’t work in this editor?

I just found out that the global variable is a property, I need to brush up on my swift. I think this site should have a book to learn swift 5 with sprite kit. This book is a little advanced for me. I am looking at video tutorials about spritekit and swift before I get back to this book.

Hi @game_gecko, welcome to the forum community! Thank you for sharing your solution. It’s always a great idea to brush up on Swift if it’s been a while, plenty of resources here. Happy coding!

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