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

2011/8/9

About pause ideas

kiarocks kiarocks

2011/8/9

#
Here is an idea for a pause method that has not been used as far as i can see.
if(buttonPressed()) { Greenfoot.setSpeed(0); }
Tell me what you think
davmac davmac

2011/8/9

#
Have you tried it - does it work? How do you unpause?
kiarocks kiarocks

2011/8/9

#
have not tried it but to start again you could make another button with code
if(buttonPressed()) { Greenfoot.setSpeed(what speed you want); } 
danpost danpost

2011/8/9

#
@kiarocks, the minimum setSpeed value according to the Greenfoot API is ONE (1), therefore, your can only create a long delay, not a pause, using setSpeed.
danpost danpost

2011/8/9

#
If you are trying to create a situation where no action is taken until a certain event occurs, like a buttonPress or keystroke, you could use: BUTTON-PRESS
boolean anyButton = false;
while (!anyButton)
{
    anyButton = Greenfoot.mousePressed(null);
}
KEYSTROKE
String myKey = "";
while (myKey = "")
{
    myKey = Greenfoot.getKey();
}
kiarocks kiarocks

2011/8/10

#
darn, you can set the slider to 0, so i thought it might be possible. didn't get a syntax error when tried
kiarocks kiarocks

2011/8/10

#
or maybe the slider is at one, is there a checkSpeed() method?
kiarocks kiarocks

2011/8/10

#
it WORKED!! no terminal window w/ error and the game is stopped.
davmac davmac

2011/8/10

#
Is it stopped, or is it just really, really slow? :)
kiarocks kiarocks

2011/8/10

#
would setSpeed bump it to one if you type 0?
kiarocks kiarocks

2011/8/10

#
what is the getSpeed method??
davmac davmac

2011/8/10

#
would setSpeed bump it to one if you type 0?
Well, as danpost pointed out, the documentation says: "The value must be in the range (1..100)". If you don't follow the rules, then there are no guarantees about what will happen. It might move the value in range, it might ignore it, it might throw an exception, or something else altogether. Even if it had some behaviour now, you couldn't be certain that it would do the same thing in a different version of Greenfoot.
what is the getSpeed method??
There isn't one.
kiarocks kiarocks

2011/8/10

#
i think a pause(int time) method would be a great thing to include with Greenfoot.
kiarocks kiarocks

2011/8/10

#
and not delay() method.
You need to login to post a reply.