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

2016/6/6

shooting a bullet every 15 iterations

Orko Orko

2016/6/6

#
how can I shoot a bullet every 15 iterations if the space bar is held down continuously ???
danpost danpost

2016/6/6

#
Orko wrote...
how can I shoot a bullet every 15 iterations if the space bar is held down continuously ???
You will just need to use an int timer field to count the iterations:
// instance field
private int shotTimer;

// in act or method called by act
if (shotTimer > 0) shotTimer--;
if (shotTimer == 0 && Greenfoot.isKeyDown("space"))
{
    shoot();
    shotTimer = 15;
}
Orko Orko

2016/6/8

#
thanks it works !
You need to login to post a reply.