Limit the Fire Rate (SFML and c++)

Started by
2 comments, last by Edward Owen 6 years, 1 month ago

Hi, I'm building a SFML and c++ Galaga clone. I'm trying to limit the amount of bullets that the player can shoot. How can I implement this "fire rate"? I was thinking to use the sf::Clock to do this, but I don't know how to implement this logic. Can anyone explain it with a simple example with one rectangle or something like this? Thank you.

Advertisement

With your time step you can use your ticks to regulate how often you can fire each shot. Once a shot is fired you would wait until (x) amount of ticks has passed before allowing the action to be preformed again. You can count the ticks by using an INT. Reset the tick tracker once a shot has been fired.

If you're confused on how to do this, you should read up on how Time Steps work.

You could also use a timer if you wish. Once the player shoots, begin tracking time, and don't allow the player to shoot until the time is equal or greater than your desired delay. Just remember to reset the tracker on every shot.

Programmer and 3D Artist

Thank you for your answer, finally I decided to implement this with a timer. It's easier for me considering that I'm still very noob in game dev hahaha. 



 

This topic is closed to new replies.

Advertisement