R
R
RasulCrosePHP2019-04-01 18:54:50
JavaScript
RasulCrosePHP, 2019-04-01 18:54:50

How to handle bullet events in the game?

I'm creating a tank game on js, I need to make it so that when the "probel" is pressed, the bullets are not drawn endlessly creating shit. You need to draw them every 2 seconds after the first bullet is drawn. Like a recharge!

//Добвляю в массив пулю
if(self.key == 32) {
        this.bullets.push(new Bullet(data.a, data.x, data.y, data.h, data.w));
        }
//Рисую их
        for(bullet in this.bullets) {
            bullet = this.bullets[bullet];
            bullet.drawBullet();
            tank.isUpdated = true;
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shamanov, 2019-04-01
@RasulCrosePHP

add a value that stores the datetime of the last shot and check it - if more than 2 seconds, then update the timer and fire a bullet

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question