Animation with flipped frames

Hi guys.
I have a problem, i need to create sprite animation with some frames without modification and some frames flipped. I can’t do this with editor GUI (Animation group can contain only sprites from atlas without any parameters). Create new sprites and add them into atlas is bad idea - atlas will be bigger than now. Do you have any idea how to do that ?

You can chain two separate animations together, one normal and one flipped:


function init(self)
  -- play firsr animation
  msg.post("#sprite", "play_animation", {id = hash("anim1")})
end

function on_message(self, message_id, message, sender)
  -- check for animation done response
  if message_id == hash("animation_done") then
    -- start the second animation
    msg.post("#sprite", "play_animation", { id = hash("anim2") })
  end
end

That was for sprites (sorry). For GUI, use gui.play_flipbook() and provide a callback function.

See https://www.defold.com/ref/gui/#gui.play_flipbook:node-animation--complete_function-

(I see that the example there is wrong, it should be:

local function anim_callback(self, node)
    -- Take action after animation has played.
end

function init(self)
    -- Create a new node and set the texture to a flipbook animation
    local node = gui.get_node("button_node")
    gui.set_texture(node, "gui_sprites")
    gui.play_flipbook(node, "animated_button", anim_callback)
end

)

Thank you for fast answer. You was right about sprite animation - i need do this for sprites, not for GUI. But is it only solution? Of course i can chain two animations inside program, but it will make code very hard for understand. I hoped that exist more simple way

Another option is to use spine bone animation. I think spine bones can be flipped on the timeline and that we support it (@sven?), or at least rotated over the x and y axis.

1 Like

Thank you, i will try

1 Like

Sorry I don’t think we support that Spine feature currently. :frowning: We really should, but I remember that I have looked into solutions for this in the past but it was quite tricky…

On the other hand we really should have the ability to flip individual frames in a flipbook animation, seems like a really good and expected feature to have!

2 Likes

Current solution to this is to use the sprite API with a direct call and complete_function callback (passed as third parameter):

    sprite.play_flipbook("#sprite", "anim1", function()
        sprite.play_flipbook("#sprite", "anim2",
    end)
1 Like