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

2023/3/3

wait()...or other?

A_User A_User

2023/3/3

#
How can you make an Actor wait 5 seconds (but in such a way that the whole game doesn't stop) and then delete itself?
danpost danpost

2023/3/3

#
A_User wrote...
How can you make an Actor wait 5 seconds (but in such a way that the whole game doesn't stop) and then delete itself?
Use an int act counter:
private int timer = 0;

public void act()
{
    if (++timer == 300) getWorld().removeObject(this);
}
The 300 is 5 times 60, or 5 seconds at 60 frames per second, which is the approximate rate at normal scenario speed of 50 (middle of speed bar).
A_User A_User

2023/3/6

#
Thanks!
You need to login to post a reply.