Well, the obvious and trivial answer would be to use the Greenfoot built-in Run/Pause button. Is there a reason not to use this one?
If you don't want to stop your scenario cold, but have a reason to keep it running while it's logically stopped, then you would need to make every actor stop acting. There are various ways to do this.
You could add a button on your screen that sets a boolean 'stopped' in the world, and all actors can check this flag (maybe via a world.isStopped() method).
So, at the top of the actor's act method, you could add
if (world.isStopped()) {
return;
}
(assuming 'world' holds a properly typed world instance).
In fact, you could make a superclass 'StoppableActor' that all your actors that should stop inherit from and put it in there.
Michael
On 24 Feb 2011, at 01:38, Aly Abed wrote:
> Hey,
> I'm a new member here, and new to the groups thing, I hope this will be very beneficial for me.
> Anyway, my question is, is there a code to make a pause button? So when I'm running the game, all I have to do is pause the game, go somewhere and I can go and unpause the game.
> Thanks
> Aly
> --
> You received this message because you are subscribed to the Google Groups "Greenfoot Discuss" group.
> To post to this group, send email to greenfoot-discuss@googlegroups.com.
> To unsubscribe from this group, send email to greenfoot-discuss+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/greenfoot-discuss?hl=en.