I’m trying to animate the alpha of a button, but i see the end_animation is executed while the button is still changing alpha, why?
I tried setting very high delay and duration to see this clearly
local function end_animation(self,node,value)
-- store the node-ID in table with value TRUE (means, animation is finished!)
self.animatedbuttons[gui.get_id(node)] = value
print("end_anim")
print(value)
end
local function animate_back_button(self, node)
if self.animatedbuttons[gui.get_id(node)] == nil then
self.animatedbuttons[gui.get_id(node)] = false
local to_color = gui.get_color(node)
to_color.w = 1.0
gui.animate(node, gui.PROP_COLOR, to_color, gui.EASING_IN, 1.4,0, end_animation(self,node,true) ,gui.PLAYBACK_ONCE_FORWARD )
end
end
Ah, you’re making a classic mistake. You’re actually calling end_animation() immediately instead of passing it as an argument to be called when the animation has finished. This is the correct line of code:
hi, if this is a classic mistake it would be helpful to add this info in the documentation. came here for the exact same problem because it is not very obvious that it is a mistake…
Well, it’s a classic mistake if you are not familiar with Lua when you pass a function as an argument. This goes for all of the API functions that takes a callback function as an argument, not only gui.animate.