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

2013/5/24

method wait() in greenfoot

kill kill

2013/5/24

#
i have a object in my world. I want to every 5 second, location of this object move(1). how can i do that??
danpost danpost

2013/5/24

#
During 'gameplay', you do not want to use methods like 'wait' or 'delay'. You need to add an int delayTimer field to the class. Each act cycle increase its value and then check it to see if it has reached some number (maybe something like 250 or 300). When it has, move the object and reset the value back to zero.
kill kill

2013/5/24

#
please, give example
danpost danpost

2013/5/24

#
Compare the following code to my last post. It was pretty much word for word.
int moveDelay = 0; // add the timer field

private void move()
{
    moveDelay++; // increment timer
    if (moveDelay == 250) // if timer has reached limit
    {
        setLocation(getX(), getY()-1); // move actor
        moveDelay = 0; // reset timer
    }
}
You need to login to post a reply.