Added precision improvements #3
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This past GGJ I developed a rythm based game, I wanted to use this library for animations but they kept getting out of sync. I had to find a workaround without using flux as I didn't have much time to find the cause.
Now that I have all the time I want I found what was causing the problem and I fixed it. My lua code style is not the best so feel free to modify any of my code.
There were two main problems, the firs one being the delay check. On a frame update it would check if the delay was grater than 0, substract the deltatime and the do nothing. If the delay is smaller than teh deltatime there is some time being "lost" in the process.
The following code would print 0, which is clearly incorrect
The second problem was relative to tween chaining. The after method used to chain tweens added an oncomplete function to the first tween that added thw new tween to the tween list. But, if the first tween didn't take up the whole deltatime, the second tween wasn't updated according to the remaining time. And again some of the deltatime was "lost".
The following code would print 1, which is clearly incorrect
These are some minor problems if time precision is not critical or you don't chain many tweens and delays, but the fixes might be useful for someone. Again, feel free to change any part of the code.