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

2014/5/7

Need a loop for my project

zworrub zworrub

2014/5/7

#
We are creating a space game where random enemies appear and you shoot them but we need to add a loop somewhere does anyone no any easy loop like a time counter or something
danpost danpost

2014/5/7

#
A basic field timer would be like this:
// add instance field
private int timer;
// is act or method it calls
timer = (timer+1)% /* max timer value */ ;
if (timer == 0) /* execute code */
The 'max timer value will normally be a number about 50 or 60 times the number of seconds to delay between executions of the code.
You need to login to post a reply.