Zombie Conga alternate game over strategy

In Zombie Conga, instead of game over scenes with images, how would you do a fly-in label with “win” or “lose” message and a button to “play again”. Basically, keeping game and score visible behind label and button instead of removing them from view.

Hi @spgms, thanks for the question! I’ve invited @caroline to the discussion as she should be able to help out more than I can :grimacing:

Let us know if you have any further questions, thanks! :+1:

1 Like

@spgms - When you do a transition, you are loading a new instance of GameScene, so all the variables are reset.

I expect you know how to do a fly-in label with an SKAction.

I’ve made this code from a SpriteKit game template. I’ve added two SKLabel nodes in GameScene.sks called playAgainButton and scoreLabel (to demonstrate keeping the score visible)

sceneDidLoad() initialises the scene and connects the GameScene.sks labels with properties.

In touchesBegan(_:with:) if the button is hidden, make it show. (That’s the win condition - you’d make a fancy method that shows the label.)
If the button isn’t hidden, then transition to a new scene.
This transition doesn’t do any SKTransitions, so the score label stays in position.

import SpriteKit
import GameplayKit

var score = 0

class GameScene: SKScene {

  var scoreLabel: SKLabelNode!
  var playAgainButton: SKLabelNode!
  override func sceneDidLoad() {
    playAgainButton = childNode(withName: "playAgainButton") as! SKLabelNode
    playAgainButton.isHidden = true
    playAgainButton.name = "playAgainButton"
    scoreLabel = childNode(withName: "scoreLabel") as! SKLabelNode
    scoreLabel?.text = "SCORE: \(score)"
  func transitionScene() {
    score += 1
    let scene =  SKScene(fileNamed: "GameScene")
    scene?.scaleMode = .aspectFill
  override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    if playAgainButton.isHidden {
      playAgainButton.isHidden = false
    if let touchedNode =
      atPoint(touches.first!.location(in: self)) as? SKLabelNode {
      if touchedNode.name == "playAgainButton" {
        transitionScene()      }
1 Like

Thanks @caroline. I will try this and see how it goes. I appreciate your help and will let you know if I have any questions.

Thanks again!

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