Hi guys, I am at that point of my game that you have to stop and refactor things that are hardcoded/bad designed to avoid that they will come back later as huge bugs.
One of the problems I am facing is the game pause, I was always using the main clock and it can't be paused.
So I created a clock myself with:
mainWorld.clock = orxClock_Create(0, orxCLOCK_TYPE_USER);
When the game is paused by pressing an UI button, I use:
Then I get the clock info, when I check the ftime, it is not changing, but the fDT is always a float number (it seems to me that is the last fDT). My question is, shouldn't it be 0?
I can save the last fTime and subtract from the new one, which will give me 0, but this is exactly what fDT should be for.
Do you still get tiny movement of your objects, even if you use pause or its just that fDT is not zero as you expected ?
For instance, my game has a monster factory struct that creates the monsters.
It creates a monster every given interval (say 0.3 seconds), that is set by the time of the factory creation (there may be more than one active factory).
Here was my code to take care of the interval (recoverd from the git repository):
My though was that with the clock paused, the fDT would be 0 and this would stop the timer to increase.
I changed the code to use the time difference instead, but I believe it would be more intuitive that the time between ticks when a clock is not ticking should be zero, not the last difference before the pause.
What you can do is check if a clock is active or not, then execute your clock related code only if its active.
The idea was that clock info would always be used from "inside" a callback or timer triggered by the clock itself. Which means that when a clock is paused, it remains invariant.
Setting the DT to 0 is only relevant when seen from outside but in which case which DT would that be?
It's supposed to represent the amount of time between two consecutive ticks, not compared with an outside referential.
Now imagine that you have two clocks, one [A] that ticks at 60Hz, and the other one varies between 15 and 60Hz.
If you look at the DT of from within an update of [A], DT won't really mean anything as sometimes there will be a single tick of between two of your observations, and sometimes you'll see multiple time the same DT (and time) as [A] will tick 2, 3 or 4 times before ticks again, which would result in wrong maths as time hasn't actually passed by for but is flowing for [A].
Does it make sense?
As a side note, what is it you're trying to do? There might be an easier way of achieving it rather than using a user clock. For example objects can be paused separately (it's also nicely wrapped up in Scroll if you're using it, including a IsPausable config property).
Basically i am coding a game that can be paused.
My Run function runs all the game logic. To calculate things such as movement and animation adjustments I use one clock and the UI uses another clock.
So when I click the pause button I just pause the clock that process the logic and I stop the physics simulation. It is working already, just my life would have been a lot easier if the paused clock returned 0 as dt.
It would take just few lines of code.
Now if I were to be using dedicated clocks, I'd probably do something like this.
When I'd go to pause I'd simply pause "GameClock" and all the logic in UpdateGame() would not be called anymore till it's unpaused.
One could even make sure all the game objects are linked to that clock so that they'll get paused as well (including all internal stuff such as spawners, FXs, ...):