My goal is to have loot drop, animate the position.y to hover on the spot for approx 1 second, then start moving towards the player. Each go.animate command is working correctly if called separately, but I want the hover to continue while the loot moves to the player.
Obviously the program isn’t happy with getting two sets of commands for position.y, so is currently ignoring the Y path towards the player in favor of continuing the hover animation.
Is there a way to ‘stack’ these animations together?
The easiest way would probably be to nest two game objects, and apply the animation to the respective object.
3 Likes
Other options to schedule or “stack” animations can be:
flow.start(function()
flow.gui_animate(node, "position.x", ...)
flow.gui_animate(node, "position.x", ...)
end)
- Or using callbacks from
animate
function:
go.animate(go, "position.x", ..., function()
go.animate(go, "position.x", ... )
end)
2 Likes
These are generally good options for sequencing animations, but in this case the user wants one animation to loop (the item hovering), with one animation playing once (go to player). I don’t think sequencing works in this case.
1 Like
Alex is correct, I’d like both animations to be running in combination rather than having them chained one after the other. Regardless of that, I hadn’t considered nesting a go.animate command within the function of another go.animate command - that will be useful in other areas moving forward!
@Alex_8BitSkull For your suggestion of nesting two game objects, would that be a similar structure to a parent/child relationship? Sorry if it’s a basic question, I’m learning Defold in an extremely non-linear way, lol
2 Likes
That’s my preferred learning style! Learn what I need when I need it to achieve something specific.
Yes, parent/child is exactly what I mean. I would probably make the hovering game object be the child of the world position object.
1 Like
The script properties can be animated. So you could define two properties (one for each movement component) and animate them in parallel. Then in the update function you could add these two properties together and copy the result in the y coordinate.
go.property("oscilation", 0)
go.property("translation", 0)
function init(self)
-- oscilate property "oscilation" between -10 and 10
self.oscilation = -10
go.animate("#scriptname", "oscilation", go.PLAYBACK_LOOP_PINGPONG, 10, go.EASING_LINEAR, 0.5, 0)
-- translate property "translation" from current value to current value + 1000
self.translation = go.get_position()
local dest = self.translation + 1000
go.animate("#scriptname", "translation ", go.PLAYBACK_ONCE_FORWARD, dest , go.EASING_LINEAR, 5, 0)
end
function update(self, dt)
-- apply the result of the animations
go.set(".", "position.y", self.translation + self.oscilation)
end
This was one of my earlier attempts at making it work, but I was missing the on_update function, which meant that it would just read the initial self.oscilation number(in your example -10) and then just sit there smugly, lol
Thanks for writing out the full example, this is exactly what I was hoping I’d be able to do!