I think you're conflating render and logic updates. The delta returned by the Gdx.graphics
object is an elapsed time value that probably should only be used for render updates, but the state an object is in is more of a game logic issue, and you generally want these things handled on different timers.
This is because if you pause your game logic (by stopping the game logic timer, so all delta times for logic are zero), you may still want some aspects of your rendering (such as, perhaps, HUD animations) to continue.
So first I would recommend you divorce your graphics and logic timers. Then, I would recommend pushing the delta time through to every object that needs it as a parameter. You can still your delta time by calling Gdx.graphics.getDeltaTime
, but do it only once at the top-most update function, and push the resulting delta down through every game or render object's own update methods. This helps decouple them from the global instance, allowing you to do better global control of timing-related effects (like slowing everything down, or pausing things as described above).
I'd also recommend moving the update of the elapsed time into an actual update()
method, and not doing it in setState
. It makes very little sense that setting the state would also advance the object's simulation time, and it means you can't call setState
more than once in an update interval without artificially pushing the clock for that object forward.