How to pause an SKSpriteNode, Swift

Miles H.

I created this game using sprite kit. During the game sprite nodes are moving. When the "Game Over" Label pops up, I would like the monster sprite node to stop moving or pause, but the rest of the scene to still move on. I know where to put the code, I just don't know how to write it. This is my monster code.

func addMonster() {

    // Create sprite
    let monster = SKSpriteNode(imageNamed: "box")
    monster.setScale(0.6)
    monster.physicsBody = SKPhysicsBody(rectangleOfSize: monster.size)
    monster.physicsBody?.dynamic = true
    monster.physicsBody?.categoryBitMask = UInt32(monsterCategory)
    monster.physicsBody?.contactTestBitMask = UInt32(laserCategory)
    monster.physicsBody?.collisionBitMask = 0
    monster.name = "box"

    var random : CGFloat = CGFloat(arc4random_uniform(320))
    monster.position = CGPointMake(random, self.frame.size.height + 20)
    self.addChild(monster)

}

EDIT

override func update(currentTime: CFTimeInterval) {

    if isStarted == true {

        if currentTime - self.lastMonsterAdded > 1 {
            self.lastMonsterAdded = currentTime + 3.0
            self.addMonster()
        }
        self.moveObstacle()
    } else {

    }
    self.moveBackground()

    if isGameOver == true {

    }

}
Maury Markowitz

If I understand your question correctly, you want to pause a single (or small number of) nodes. In that case...

monster.paused = true

Is probably what you want.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related