Hi,
I have quite a large animation (many frames, each frame is quite large too), so my resulting sprite sheet having all animation frames on it was too large to be handled by the device (iPad 1). This caused my animations freeze.
Since I can’t really do anything about the artwork (I’m just a contractor in this project) I needed to deal with it instead of just changing how the animation works.
So my initial idea was to divide the huge sprite sheet info several smaller ones - so no single texture is larger then allowed.
But - as I see, a single sequence can’t contain more then a single texture. Which makes a lot of sense :))
Now the option that comes to my mind is to create a sequence from each of the textures (so frames 1-11 are in sequence 1, 12-22 are in sequence 2, etc) and then when I animate the sprite listen to “sprite” kind of events and when the animation sequence finishes, in the listener, change the sequence to the next one and run the animation again. And loop the behaviour like this.
So the code could look like this:
local sprite = ... sprite.sequences = { "seq1", "seq2", "seq3" } sprite:setSequence ( "seq1" ) sprite.sequenceIdx = 1 sprite.eachFrameDelay = 60 -- how long should we wait after getting to the last frame to show the next one? sprite:addEventListener ( "sprite", function ( event ) if event.phase == "ended" then local nextSeq = sprite.sequenceIdx + 1 if nextSeq \> #sprite.sequences then nextSeq = 1 end timer.performWithDelay ( sprite.eachFrameDelay, function () sprite:setSequence ( sprite.sequences [nextSeq] ) sprite:setFrame ( 1 ) sprite:play () end ) end end )
Does this make sense, or should I try to think about some better solution?