Search code examples
sprite-kitentity-component-system

SpriteKit Entity Component System - cooldown timer with display element


In an Entity Component System, what's the correct way to create a cooldown timer that has a display element that could be attached to a button for example?

My initial thought is to separate out the timer and progress bar components individually whereby the timer either delegates back to the entity to update a progress bar via a specific number/percentage or the timer tries to grab the correct component from the entity itself and update it. This way I've split up all the concerns into separate components. But should this actually all be in one component such as a timerProgressBarComponent seen as it's "one job". Ideally this will add a display element to an existing sprite to showcase how long is left.

In case you want some more context, I'm thinking in terms of a button at the moment that can only be pressed every 10 seconds, but I want to update the ui with an indication of how long is left and once the 10 seconds is up make the button tappable again.


Solution

  • There is no "correct way" only what you prefer. If I was doing this, I would separate out timer to allow for various types of progress bars, but that does not mean that it is not feasible for a progress bar to contain its own timer and still act as a single component.