Timeline for XNA Health Bar continually decreasing
Current License: CC BY-SA 3.0
7 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Mar 22, 2013 at 8:50 | comment | added | Stig-Rune Skansgård | This is good IF you want a stepping decrement. But as the OP does not specify this, we can asume that making currentHealth a float and decreasing it by ElapsedGameTime.TotalSeconds will do the trick. | |
Nov 25, 2012 at 21:32 | history | edited | DMan | CC BY-SA 3.0 |
added 10 characters in body
|
Nov 25, 2012 at 21:31 | comment | added | DMan |
1. gameTime.ElapsedGameTime.Milliseconds gives the elapsed game time since the last update. It will be reset to zero every frame automatically. 2. I agree with you on this; I considered it. However, I doubt it's 'normal' for a frame to take more than a few milliseconds to update, and so the timer will be off by only a maximum of those few milliseconds, not seconds. As a quick fix, just subtract 1000 as opposed to resetting to zero.
|
|
Nov 25, 2012 at 20:21 | comment | added | Philipp |
This solution doesn't look right to me. 1. you seem to assume that gameTime.ElapsedGameTime.Milliseconds; gets reset to 0. Doesn't it increase more and more while the game is running? 2. when more than 1000 milliseconds elapsed, let's say 2200, you still only reduce the health by one. It should be decreased by 2, and the 200 remaining ms should be somehow carried over to the next loop iteration.
|
|
Nov 25, 2012 at 19:59 | comment | added | Craig | perfect, cheers! :D | |
Nov 25, 2012 at 19:58 | vote | accept | Craig | ||
Nov 25, 2012 at 19:53 | history | answered | DMan | CC BY-SA 3.0 |