Skip to content

Commit

Permalink
Fix for edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Insality committed Nov 13, 2024
1 parent 5ceacb8 commit 4fb57bf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion game.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bootstrap]
main_collection = /example/example.collectionc
main_collection = /test/test.collectionc

[script]
shared_state = 1
Expand Down
7 changes: 7 additions & 0 deletions test/test_tweener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tweener/tweener.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4fb57bf

Please sign in to comment.