Hey, everyone. I’m working on an engine for a simple game. The PLAY state has two sub-states: RUNNING and PAUSED. I need to be able to put any number of text items on the stage, have each stay there for a predefined period of time, and then fade at a predefined rate. Once the fade is complete for a text item, it should be removed from the stage and nullified. Here’s where I’ve got a question: I need to make sure that, if the game state is PAUSED, the delay or fade is paused as well.
When the PLAY sub-state changes from RUNNING to PAUSED (and vice versa), it’s easy enough to pause and resume the gameplay components (sprites, etc.) en masse. For example, if all of the gameplay components are updated from a single function call in the PLAY loop, that call can be suppressed while the sub-state is PAUSED. That doesn’t completely resolve the issue, though.
I need to make sure that the fading and removal actions are triggered based on the cumulative time the text item has been on the stage while the game is RUNNING – not just the amount of time that has passed since it was added to the stage. How would you accomplish that?
Should the text items each have their own Timer objects (and be paused and resumed accordingly)?
Alternatively, should the text items use some type of counter to determine how much time has passed? (The suggested counter would be incremented only while the PLAY sub-state is RUNNING.)
I’m interested in hearing your thoughts on the validity and efficiency of these approaches, as well as any additional suggestions you might have. Thanks!