How to programmatically set a specific frame for a tilesource based animation

Hi All!
I’m really new to Defold and I am trying to explorer its features.
In a game prototype I have a Game Object with a Sprite; the sprite is a Tile Source based animation, but what I really need is to programmatically set one frame or the other based on a program logic.
I didn’t find an API function that does that.
Is there something like: sprite.set_frame(<frame_number>) ?
The frameset is about 120 pictures, so I would like to avoid creating 120 single small PNG files.

Can anyone help?
Thanks.

1 Like

You can create animations in a tilesource. You need to create one for each animation/image you wish to set and use sprite.play_flipbook().

1 Like

Use go.set("#sprite", "cursor", frame_number / frame_count)
frame_number and frame_count zero based, i.e. in your case 0…119 / 119.

2 Likes

Huh, yeah, we have the sprite cursor now! Would you have to do a math.floor() as well? And do you need an animation that spans all of the tiles in the tilesource?

1 Like

The cursor is between 0 and 1, so a floor() would only clamp it to 0.

2 Likes

Oh, yes, that’s true! My bad.

1 Like

That’s exactly what I was looking for!
Thanks

1 Like