de-Roo.Lukas Posted June 11, 2018 Posted June 11, 2018 (edited) I want to add a number by 1 every 0.01 second. but it seems that no matter how did I change the CHANGE_INTERVAL , the largest number I can get is around 3500 every minute, I want it to be 6000/min the codes are as follows: int bulletNumber; const float CHANGE_INTERVAL = 0.01f; float elapsed_time = CHANGE_INTERVAL; void fire() { if (elapsed_time < 0.0f) { bulletNumber += 1; elapsed_time = CHANGE_INTERVAL; } elapsed_time = elapsed_time - Game::get()->getIFps(); // Log::message("%d \n", bulletNumber); } Edited June 12, 2018 by de-Roo.Lukas
Greg.Mildenhall Posted June 12, 2018 Posted June 12, 2018 What's the point of adding 1 a thousand times a second? Can you really show a user-visible change in reaction to that number a thousand times a second? Say you're rendering (or ticking physics) at 50 frames per second. Then there's no reason you can't add 20 all at once each frame. It'll be the same result by the time you get to the frame logic where you need to _use_ the number.
de-Roo.Lukas Posted June 12, 2018 Author Posted June 12, 2018 sorry it is 0.01 second, I want to stimulate a minigun which will shot 6000 bullets/ min and I want to show the bullets number.
Greg.Mildenhall Posted June 12, 2018 Posted June 12, 2018 Are you just trying to do this: void fire() { elapsed_time += Game::get()->getIFps(); bulletNumber = int(elapsed_time*100); } Once a frame whenever bullets are being fired? 1
de-Roo.Lukas Posted June 12, 2018 Author Posted June 12, 2018 (edited) Thanks, Greg I tried, it works. Thanks for your solution! Edited June 12, 2018 by de-Roo.Lukas
Recommended Posts