0

I am struggling with my first semi basic game for iPhone. The game operates well but I want a button to display saying restart and then when clicked it restarts the scene. This button should only appear when my sprite (called sprite) falls below the bottom of the iphone screen. I am using both cocos 2d and box 2d if that makes a difference.

Thank you for the help in advanced, it is greatly appreciated!

user1432813
  • 162
  • 2
  • 10
  • Is your problem getting the button to only appear after the sprite falls, getting the button to reset the scene, or both? – BobbyScon Jul 06 '12 at 18:09

1 Answers1

0

Quick answer for having the button appear once the sprite falls below a certain point: When you create the button, set its state to not visible. resetButton.isVisible = NO; Then write an if statement about your sprite's position and enable the button once that happens.

if (sprite.position.y >= 0)
{
    resetButton.isVisible = YES;
}

This should get you started on that aspect. I'm not at my Mac right now, but if memory serves, a non-visible button is not enabled, so clicking on its location won't matter. If that's incorrect, just add in resetButton.isEnabled = NO; and YES appropriately.

As for resetting the scene, this can get a little tricky depending on what exactly you want to accomplish. You need to essentially replace the scene with itself, but this can cause undesirable flashes. A quick google search found a bunch of forum posts on this. If you can elaborate on what you've already tried and where you're getting caught up, I can try and get more specific.

BobbyScon
  • 2,537
  • 2
  • 23
  • 32
  • I'd really recommend going through some of the many tutorial sites out there that will cover these topics extensively, especially for this style of game. http://www.raywenderlich.com/tutorials is one of my favorites. – BobbyScon Jul 06 '12 at 18:33
  • Cheers man, fantastic. It appears to be the department of the bleeding obvious and I feel so stupid thank you! – user1432813 Jul 06 '12 at 18:37
  • You're welcome, I've had plenty of those moments myself! Things usually sound more complicated than they really are. – BobbyScon Jul 06 '12 at 18:41