Hello, I'm a playdate newbie. I'm trying to create a simple three-frame explosion for a Bosconian clone (gotta start somewhere), using playdate.graphics.animation.loop
Initially, I was trying to start them paused, so I'd only animate them onscreen as required. However, it seems the timer is running from loop creation, resulting in an oddly looping animation. It's odd because the loop was created with loop = false as well, and the length of the repeated animation is obviously dependent on when the game started.
For example this code (where you can see me trying to manage the paused state):
import 'Corelibs/animation'
local gfx = playdate.graphicsExplosion = {}
Explosion.__index = Explosionfunction Explosion.new()
local imgTable, err = gfx.imagetable.new("images/explosion-table-15-15.png")
assert(imgTable, err)local self = gfx.animation.loop.new(120, imgTable, false) self.paused = true self.x = -100 -- Start offscreen self.y = -100 function self:update() if self:isValid() then self:draw(self.x - 7, self.y - 7) else self.isPaused = true end end function self:explode(x, y) self.x = x self.y = y self.frame = 1 self.paused = false end return self
end
Results in this animation. The first time 'explosion' is used, the animation loops, subsequent times it appears to play the three-frame loop without issue:
Two questions:
-
Does it even matter? Can I have a handful of these explosion animation loops that I can re-use? If I start them off-screen their first animation loop can run through, and subsequent times setting frame = 1 seems to work fine when they appear onscreen. Do I even need to care about trying to pause animations when not in use?
-
Is this generally how people use animation.loop for non-looping animation? Create them, leave them offscreen or undrawn but leave the timers running? Much processor cost to doing this?
If I remove the clumsy attempts to manipulate self.paused, it works fine:
That's with this code:
import 'Corelibs/animation'
local gfx = playdate.graphicsExplosion = {}
Explosion.__index = Explosionfunction Explosion.new()
local imgTable, err = gfx.imagetable.new("images/explosion-table-15-15.png")
assert(imgTable, err)local self = gfx.animation.loop.new(120, imgTable, false) self.x = -100 -- Start offscreen self.y = -100 function self:update() if self:isValid() then self:draw(self.x - 7, self.y - 7) end end function self:explode(x, y) self.x = x self.y = y self.frame = 1 end return self
end
Any help greatly appreciated!