Hi,
In my game, I have a spaceship that has a certain amount of energy which is displayed as bar (image) that decreases in width as the ship’s energy decreases (i.e. like a classic arcade “fuel meter”). At the end of a level, I want an animation consisting of the energy bar rapidly decreasing in width at the same time as a text (newText() object) is counting up to show the score (the score is a function of the amount of energy left).
The animation of the energy bar and the score text update must be in perfect sync so that when the energy bar has a width of 0, the score counter has reached the actual score. The length of the animation is 2 seconds.
Below, you see my attempt at this, but using an enterFrame listener at the same time makes the animation of the energy bar jerky, and not smooth (performance issue, I guess). What would be a better way of doing this so that both animations are perfectly in sync?
local function animateScore( if (energyBar.width \> 0.0) scoreText.text = math.floor(score - (energyBar.width / energyBarInitialWidth \* 100)) else Runtime:removeEventListener("enterFrame", animateScore) end end Runtime:addEventListener("enterFrame", animateScore) transition.to(energyBar, { time = 2000, width = 0.0 })