From 4fb57bf0aff31a2b53c1f460e7f14d1ee613e649 Mon Sep 17 00:00:00 2001 From: Insality Date: Wed, 13 Nov 2024 18:09:23 +0100 Subject: [PATCH] Fix for edge cases --- README.md | 3 ++- game.project | 2 +- test/test_tweener.lua | 7 +++++++ tweener/tweener.lua | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bac41a8..552d5ab 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,9 @@ update_frequency = 60 -- Tween function can be a string, a predefined easing function, or a custom easing function local tween_function = "linear" or tweener.linear or go.EASING_LINEAR or gui.EASING_LINEAR or {0, 0.2, 0.4, 0.8, 0.9, 1} -tweener.tween(tween_function, from, to, time, callback, [dt]) tweener.ease(tween_function, from, to, time, time_elapsed) +tweener.tween(tween_function, from, to, time, callback, [dt]) -- Returns tween_id +tweener.cancel(tween_id) ``` ### Importing the Module diff --git a/game.project b/game.project index 0b40c98..355841c 100644 --- a/game.project +++ b/game.project @@ -1,5 +1,5 @@ [bootstrap] -main_collection = /example/example.collectionc +main_collection = /test/test.collectionc [script] shared_state = 1 diff --git a/test/test_tweener.lua b/test/test_tweener.lua index 34749b3..abc4e74 100644 --- a/test/test_tweener.lua +++ b/test/test_tweener.lua @@ -31,6 +31,13 @@ return function() assert(tweener.ease(easing, 0, 100, 1, -1) == 0) assert(tweener.ease(easing, 0, 100, 1, 0) == 0) assert(tweener.ease(easing, 0, 100, 1, 2) == 0) + + -- Non from zero + assert(tweener.ease(easing, 100, 200, 1, 0) == 100) + assert(tweener.ease(easing, 100, 200, 1, 0.25) == 200) + assert(tweener.ease(easing, 100, 200, 1, 0.5) == 300) + assert(tweener.ease(easing, 100, 200, 1, 0.75) == 200) + assert(tweener.ease(easing, 100, 200, 1, 1) == 100) end) it("Tweener should support each Defold tweening", function() diff --git a/tweener/tweener.lua b/tweener/tweener.lua index 409b1d4..60cc927 100644 --- a/tweener/tweener.lua +++ b/tweener/tweener.lua @@ -112,10 +112,10 @@ function M.custom_ease(easing, t, b, c, d) local time_progress = t / d if time_progress >= 1 then - return (c + b) * easing[sample_count] + return c * easing[sample_count] + b end if time_progress <= 0 then - return b * easing[1] + return b + (c * easing[1]) end local sample_index = sample_count - 1