Jump to content
  • Advertisement
Sign in to follow this  
ecr0n

Delays?

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

y0 I have a problem. I was able to figure out how to draw bullets using an array. The bullets right now are currently pixels while i'm in the process in developing my game(Windows/C++). The problem i'm having is that when the key is pressed to shoot the computer draws many pixels making it form a straight line or a diagnol line if the player is moving. How could i fix this? Is there a way for me to put a delay on it? so the player can't hit the shoot button but a couple times a second or something?...

Share this post


Link to post
Share on other sites
Advertisement
I would use the Windows functionality to get the tick counter, and then update it every frame.

Pseudocode:
while(bGameIsRunning) {
...tickStart = get ticks from system counter
...// game stuff goes here
...bulletTimer += ticksElapsedLastFrame;
...if(player pushes fire and bulletTimer is over x number of ticks)
.....fire
.....bulletTimer = 0
...ticksElapsedLastFrame = get ticks from system counter - tickStart
}

I'm not sure of the exact syntax under Win32, otherwise I would have put it in there instead of pseudocode. Basically, you take a measure of how many "ticks" (ms) there are between frames, and then continuously update the timer. When the player mashes the button, you check the timer to see if it's over a certain number, and if it is, you reset it to zero and fire the bullet.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!