0

I'm near the end of developing a game, and long story short, the game will be over when an object crashes into one of the obstacles. I've got that part down and the game runs really well by itself, but there is one more step I am looking to add in.

I would like to add in an in-app purchase of a 'play on' feature, that is, starting where the user's game originally ended so they can continue on. I'm okay with in-app purchases on the whole, but I guess what I want to know is how does one make it possible to 'play on' following the in app purchase? I'm just looking for something basic I can build on.

I'm a Stack newbie, as I've only created an account today (but I've been programming for a little while and this site has helped me so many times), so I'm sorry if there has been a duplicate thread made elsewhere. I did look around for an hour or so before deciding to post (and Google was no help).

jlp28
  • 53
  • 1
  • 10

1 Answers1

0

As a general stack overflow rule you should always post some of your own code or what code you have played around with.

I am actually also looking to integrate a playOn button in my game. Now I haven't actually found the perfect solution for this yet but hopefully this helps you get on the right track.

Step 1: How have you programmed your game over scenario? Are you just pausing the scene, are you pausing nodes or are you removing all children from your scene?

The way I pause my scene is by creating a worldNode and than adding all objects that I need paused to the worldNode. You can read my two answered questions for more detail

Keeping the game paused after app become active?

Sprite moves two places after being paused and then unpaused

This way when I pause my game I dont actually pause the scene which gives me more flexibility adding pauseMenus etc. Furthermore its seems smoother than pausing the skView.

I also call pause when the player died, which means I could resume the enemies/obstacles from where they left of if I call resume. So my game over method looks like this

func gameOver() {
    pause() // call pause method to pause worldNode etc

    //show game over screen including playOn button
}

Step 2: Now in regards to respawning the player, it depends on how he is positioned, how far he can move etc. If your player is mostly in the same area than you can probably just respawn you player manually once "PlayOn" is pressed and than resume the game as if it was just paused.

So once your playOn button is pressed you can call a method like so

func playOnPressed() {

    // Remove current player
    // Doesnt have to be called, you could just change the position
    player.removeFromParent()

    // Add player manually again to scene or just reposition him
    ...

    // Remove obstacle that killed player
    // haven't found a great solution for this yet

    // You could make the player not receive damage for 5 seconds to make sure you dont die immediately after playOn is pressed

    // Call resume method, maybe with delay if needed
    resume()
}

If your player position could be all over the screen, as in my game, I have been playing around with a few things so far.

I created a position property to track the player position

playerPosition = CGPoint!

and than in my scene update method I constantly update this method to the actual position of the player.

override func update(currentTime: CFTimeInterval) {
    if gameOver = false {
          playerPosition = player.position
    }
}

I than have been playing around with the "playOnPressed" method,

func playOnPressed() {


    // Remove current player
    //Doesnt have to be called, you could just change the positioon
    player.removeFromParent()

    // Add player manually again to scene or just reposition him
    ...
    player = SKSpriteNode(...
    player.position.x = playerPosition.x - 40 // adjust this so it doesnt spawn where he died but maybe a bit further back
    player.position.y = playerPosition.y // adjust if needed

    // Remove obstacle that killed player
    // haven't found a great solution for this yet

    // You could make the player not receive damage for 5 seconds to make sure you dont die immediately after playOn is pressed

    // Call resume method, with delay if needed
    resume()
}

I hope this helps you playing around with your playOn button, if someone has a better way I would also appreciate it immensely.

Community
  • 1
  • 1
crashoverride777
  • 10,581
  • 2
  • 32
  • 56