Constant rate of fire


how can I get it working, that the performAction of my FireBullet Class is only called for example every 1/10 second when the mouse button is pressed.

I need that because when I press the mouse button, that method is called every frame and so the firing rate is too high and too many bullets are fired… I should be constant and it should not depend on the fps (), cause fps are different on each PC.

Thank you guys!

(btw: sorry for posting so much questions ;o)

Use the Timer and keep a long var of how much time has passed since the last time you fired.  In SimpleGame there is a tpf var that is how much time has passed since the last update was called.

So, something like:

lastShot += tpf;
if (isShooting() && lastShot > .1f) {
    lastShot = 0;

that's it :slight_smile:

didn't know that it was so easy :smiley:

i love this engine

thank you renanse…you rule ;D