[SOLVED] Animate (tint.w) for duration > 0.1 won't execute callback

Hello guys, happy new year 2025! Hope everybody have a great new year better than last year.
I’m new to Defold, and still trying to get my feet wet.
I have a question, I’m trying to animate tint.w to 0 in some duration. The fading animation goes great in every duration value, except if the duration > 0.1, the callback doesn’t get executed, otherwise it gets executed. I searched this forum for similar issue and tried the solution but can’t get it work as expected.
What may I’ve done wrong? Here is my code:

function init(self)
	self.t = 3 -- <1>
end

function update(self, dt)
	self.t = self.t - dt -- <2>
	if self.t < 0 then
		go.animate("#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 0, 0, function()
			print("deleted") 
			go.delete() 
		end)
	end
end

For additional context: the sprite is a shuriken that is thrown by character when it receive user action.
Thank you very much.

When self.t < 0 you run animate again and again every frame. Every new animate function call override old one, so you don’t get callback.

3 Likes

Thank you for pointing me out :grinning:. I change the code to the following, and it works:

function init(self)
	self.t = 3 -- <1>
	self.expire = false;
end

function update(self, dt)
	self.t = self.t - dt -- <2>
	if self.t < 0 and self.expire == false then
		go.animate("#sprite", "tint.w", go.PLAYBACK_ONCE_FORWARD, 0, go.EASING_LINEAR, 1, 0, function()
			print("deleted") 
			go.delete() 
		end)
		self.expire = true
	end
end
2 Likes