Lightweight AnimatedImage Library

Also handy:

function AnimatedImage:getImage()
	return self.image_table:getImage(self.loop.frame)
end

I’ve got my modified version here:

I’m really not sure about etiquette when it comes to stuff like this. Would you prefer I call it something else if it’s public?

Thanks Dustin it's very useful. Just wondering if we are able to know the animation has ended without having to know the index and doing a check?

That's fine. You could also submit a pull request to merge your change in vs having two separate repos for the same code. Or at the very least branch off mine. Not a big deal of course. :slight_smile:

1 Like

This is awesome! Thanks to your help I am one percent less code-rookie now (: Thank you.

1 Like

I have the same question as jmation. Wanting to basically perform an action when an animation has ended. I could hard-code a check against the last frame, knowing how long the animation is, but a :getEndFrame() would be amazing in addition to what's there.

Is there some other way of doing this I'm not thinking of?

Thank you so much for this, this is how I expect and hope animated images might work in the SDK proper in future :slight_smile: Super easy to work with.

Take a look at Nic's sequence library.

Latest download at GitHub, see end of the post below.

Thanks matt, I'll check it out :slight_smile:

Thanks for this! I used it to add a simple animation to my title screen, a timer resets its index so it loops with a delay. Removed a decent chunk of setup code

I've added an isComplete() function to AnimatedImage. However, this will always return false for looping animations.

2 Likes

Thanks so much! While a minor thing, I'm looking forward to replacing this in my code :slight_smile:

if self.coinExplode:getFrame() >= 7 then
1 Like

Added this function, thanks. :slight_smile:

1 Like

Also just noticed how you're using getImage() in the sprite example. Though this works fine, you could also just pass in the animated image directly as it is designed to act as a proxy to the current frame's image, which is the whole point of the class: graphics.image but animated. :slight_smile:

1 Like

While you're here in the thread Dustin, I took your assertion above of "image but animated" literally and tried using it with :setImage() on a sprite, but no dice. Is getting it working with sprites via this method way outside the scope of this, or something viable in future?

I have zero idea how hard this is. Just wishing Playdate SDK had better built in stuff for handling animated sprites :slight_smile:

Oh that makes sense now that I think of it. I suppose any part of the API where the lua object is handed off to C this may not work. It works when Lua code expects an image and calls image methods on the AnimatedImage object, but if it gets handed over via C and C is casting to a graphics.image object, this will probably.

Good point. Thanks!

:slight_smile:

Brought this into AnimatedImage. Also made it so you can simply pass in an image table if you have one already loaded—which you may if you are thinking about using the sequence param where you can now select individual frames from a larger image table.

Thanks! Good add.

1 Like

Definitely sense-check this, but it seems like isComplete() is returning false when the animation is complete, when I'd expect it to return true?

function AnimatedImage:isComplete()
	return self.loop:isValid()
end

should this be:

function AnimatedImage:isComplete()
	return not self.loop:isValid()
end
1 Like

You know, sometimes you think you're good enough to just write some code and commit without testing. Then the world slaps you in the face and says "NO."

Anyway, should be fixed. Thanks. :stuck_out_tongue:

3 Likes

All good, thank you. I thought I was going insane there for a minute. :smiley:

isComplete seems like a valid state to me. :wink:

1 Like

false. I mean true. :wink: