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

2013/5/15

Help with timers

Yongjoon Yongjoon

2013/5/15

#
I'm trying to get some timers to make some minions to move autmatically. The thing is, I have no idea how to use timers. Could someone help me? Thanks
danpost danpost

2013/5/15

#
Timers are useful only to regulate the rate of speed at which something happens and are not necessary in creating automatic movement to begin with. The running of the scenario, with it executing all act methods on all active objects repeatedly will create the 'loop' required to continuously have your actors do something. For example, just by creating an 'act' method with a simple 'move' statement will cause your actor to move toward the right until it hits the edge of the world just by starting the simulation.
// in an actor class
public void act()
{
    move(1);
}
This repeated execution of the act method can be used to continuously update properties for the actor; such as its rotation (to make it look and move a different direction), it image (to create animation), its speed, etc. It can also be used to continuously check for obstacles or the edge of the world; as well as many other things (including keeping any timer fields you have added to the class updated).
You need to login to post a reply.