defold-tweener icon indicating copy to clipboard operation
defold-tweener copied to clipboard

Added looping for tween timer

Open leoska opened this issue 3 months ago • 1 comments

I faced the need for an infinite repeating timer, similar to how go.animate does it with go.PLAYBACK_LOOP_FORWARD.

At first, I tried to recreate the timer on every final_call, but because of timer recreation and some specifics of the Defold engine, I ended up skipping a frame.

local function get_tween(self, from, to, callback)
	return tweener.tween(consts.CUSTOM_EASING, from, to, consts.ANIMATION_SPEED_IDLE, function(value, is_final_call)
		callback(self, value)

		if is_final_call then
			self.tween = get_tween(self, from, to, callback)
		end
	end)
end

https://youtube.com/shorts/_tbI0QzhfFE?si=hhX5-cNtpVy8Bsaw

That’s why there was a need to avoid recreating the timer and instead just “restart” it from the beginning.

leoska avatar Sep 07 '25 14:09 leoska

Hello, thanks for the PR and issue

The loop parameter seems really needed by some users, but the suggested changing of params leads to breaking changes

I will check for better solution and better API (it becomes quite huge!)

Isn't this working as intended?

local function start_looping_tween()
	local looped_tween = tweener.tween(gui.EASING_OUTSINE, 0, 100, 1, function(value, is_final_call)
		print("Looped tween value: " .. value)
		if is_final_call then
			start_looping_tween()
		end
	end)
end

start_looping_tween()

Insality avatar Sep 08 '25 15:09 Insality