This site requires JavaScript, please enable it in your browser!
Greenfoot back
ianking
ianking wrote ...

2011/8/6

Changing scenario speed within a program

ianking ianking

2011/8/6

#
Is there a way of changing the scenario speed from within a program? I'd like to pause a program at a particular point until a key is pressed.
GameCode GameCode

2011/8/6

#
Yes there is. You could stop the scenario with Greenfoot.stop(); (Then you can only go on with clicking the run-Button) Or you could change the speed with Greenfoot.setSpeed(...);
ianking ianking

2011/8/6

#
Many thanks.
mjrb4 mjrb4

2011/8/7

#
Note though that as GameCode said - if you use Greenfoot.stop() you can't resume by a key press since there won't be any code running to check that key press! If you want to go down that route (i,e, resume from a key press), then the easiest way would probably to have a "paused" boolean field in the relevant actors, and invert it whenever a particular key is pressed. You'd then only execute the main body of the act method if paused was set to false.
You need to login to post a reply.