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

2015/7/23

How can I get rid of an object after a certain amount of time?

ava9 ava9

2015/7/23

#
How can I create a timer so an object will disappear after a certain amount of time?
danpost danpost

2015/7/23

#
ava9 wrote...
How can I create a timer so an object will disappear after a certain amount of time?
In the act method of the class of the object to be removed, place code similar to the following:
timeCounter--;
if (timeCounter == 0) removeObject(this);
This may or may not be the exact coding you would use (it is just a format to follow -- and not complete, at that). You will need 'timeCounter' declared as an 'int' field within the class. The initial value of this field determines how long the object is to remain in the world before being removed. Normally, 55 would represent about one second of time.
wabuilderman wabuilderman

2015/7/23

#
You CAN use system time but that is complicated and is only really necessary for something that is like clockwork.
You need to login to post a reply.