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

2013/1/14

Making an actor not world delay?

bbwf bbwf

2013/1/14

#
Hey is there a code for delaying an actor not the whole world?
danpost danpost

2013/1/14

#
To delay an actor, you will need a counter to count down the time that the actor is to be delayed. While the counter is not zero, the delay is in effect; if the counter is zero, the actor can act as normal. Just set the value of the timer to the appropriate value to create the delay required (usually about sixty times the number of seconds delay time). Start your 'act' method for the actor as follows:
public void act()
{
    if (counter>0) counter--; // if delaying, run timer
    if (counter>0) return; // if time not elapsed, exit method
    // do what you normally would do (not delaying)
}
To set up the counter, you just add an instance int field to the class of the actor:
private int counter;
You need to login to post a reply.