Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong frame duration for first and last frames #32

Open
eduardomezencio opened this issue Jul 31, 2018 · 3 comments
Open

Wrong frame duration for first and last frames #32

eduardomezencio opened this issue Jul 31, 2018 · 3 comments

Comments

@eduardomezencio
Copy link

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.

@martin-braun
Copy link

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.

@eduardomezencio
Copy link
Author

Sure, I just wanted to be sure he would approve it. I'll do it later tonight.

@eduardomezencio
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants