You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a problem that will only happen if increments to timer are discrete units, so it does not happen in the demo, where dt is used for increment.
Create an animation with frame duration 4, and then update it each frame with animation:update(1). Each frame in the animation should be displayed for 4 game frames. With the current anim8 code, while every inner frame shows with the correct duration, the first frame always shows for one frame more and the last frame for one frame less than expected. Let's say I have this animation with 4 frames, with each frame with duration 4. Instead of seeing the expected 1111 2222 3333 4444 1111 ... loop, I see 11111 2222 3333 444 11111 ... .
I corrected this for use in my personal project, and I think my modification could be also applied in the official anim8 code . The change is as follows:
This line in Animation:update: local loops = math.floor(self.timer / self.totalDuration)
Becomes: local loops = math.ceil(self.timer / self.totalDuration) - 1
(I also changed the next line if loops ~= 0 then to if loops > 0 then to make it clearer, but it's not necessary)
floor(x) is the same as ceil(x) - 1, except for integer numbers. (floor(1.2) == ceil(1.2) - 1, but floor(1.0) != ceil(1.0) - 1)
And that's exactly what causes this problem, because the frame should change only when loops is greater than 1 and not when it's exactly equal to 1. And that's also what makes it not appear when dt is not given as discrete units, since chances are you'll never get an exact number if you keep adding dt.
The text was updated successfully, but these errors were encountered:
Could you please make a pull request out of this? I think kikito seem to be pretty busy at the moment, a pull request would make things easier on his side.
I still haven't done the pull request because I found a little conflict between what I did and the commit 902b418. They are related, but it seems like it does not solve my problem and the two changes together also don't work correctly. I'll have to wait until I have some time to check this carefully and ensure the logic is correct.
This is a problem that will only happen if increments to timer are discrete units, so it does not happen in the demo, where dt is used for increment.
Create an animation with frame duration 4, and then update it each frame with
animation:update(1)
. Each frame in the animation should be displayed for 4 game frames. With the current anim8 code, while every inner frame shows with the correct duration, the first frame always shows for one frame more and the last frame for one frame less than expected. Let's say I have this animation with 4 frames, with each frame with duration 4. Instead of seeing the expected 1111 2222 3333 4444 1111 ... loop, I see 11111 2222 3333 444 11111 ... .I corrected this for use in my personal project, and I think my modification could be also applied in the official anim8 code . The change is as follows:
This line in
Animation:update
:local loops = math.floor(self.timer / self.totalDuration)
Becomes:
local loops = math.ceil(self.timer / self.totalDuration) - 1
(I also changed the next line
if loops ~= 0 then
toif loops > 0 then
to make it clearer, but it's not necessary)floor(x)
is the same asceil(x) - 1
, except for integer numbers. (floor(1.2) == ceil(1.2) - 1
, butfloor(1.0) != ceil(1.0) - 1
)And that's exactly what causes this problem, because the frame should change only when loops is greater than 1 and not when it's exactly equal to 1. And that's also what makes it not appear when dt is not given as discrete units, since chances are you'll never get an exact number if you keep adding dt.
The text was updated successfully, but these errors were encountered: