We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Restart a game
Page Index Toggle Pages: 1
Restart a game (Read 969 times)
Restart a game
Jun 12th, 2009, 5:55am
 
Hi,

i created a simple game and want to implement a restart screen if the game is finished.

I tried this with 2 states and said: if state =0 run game, state =1 start screen.

The problem is, the game is always running in the background when i come to state1. If i klick on a button at the restart screen now i come back to the game but the game doesnt start new it starts at the postition where it has end.

Are there a command to start an sketch completely new without clicking the newstart button of the sketch at the upper left side?
Re: Restart a game
Reply #1 - Jun 12th, 2009, 6:45am
 
Quote:
The problem is, the game is always running in the background when i come to state1. If i klick on a button at the restart screen now i come back to the game but the game doesnt start new it starts at the postition where it has end.


Since your game picked up where it left off the game was probably not running in the background rather it was 'paused'

Without being able to see the code this will be rather non-specific. When your game first starts you use setup to create your game objects and initialise them to their starting values. What you need to do is reinitialise the game objects to the startup values when you click on the restart button e.g.
Code:


void setup(){
  size(...);
  // create the game objects
  iniyialiseGame9);
}

void initialiseGame(){
  // set the initial values for the game objects
}


Whenever you want to restart the  gane first call the initialiseGame() method.
Re: Restart a game
Reply #2 - Jun 12th, 2009, 8:13am
 
Thank you, now its working Smiley
Page Index Toggle Pages: 1