jeremyckahn / shifty

The fastest TypeScript animation engine on the web
https://jeremyckahn.github.io/shifty/doc/
MIT License
1.54k stars 88 forks source link

Interpolate #5

Closed joelambert closed 13 years ago

joelambert commented 13 years ago

Thanks for the interpolate function, seems to be working a treat!

I did notice that the color plugin wasn't working and was throwing an error when trying to tween color params. Here's a bug fix that I've tested with interpolate but not under normal usage.

Here's an example of code that would throw the error pre-fix:

var test = Tweenable.util.interpolate({
    width: '100px',
    opacity: 0,
    color: '#FFF'
}, {
    width: '200px',
    opacity: 1,
    color: '#000'
}, 0.5);

Same example works with this patch

jeremyckahn commented 13 years ago

Thanks for finding the bug and submitting this patch, Joe. One of the ways that I optimize Shifty is by minimizing the amount of error and type checking, at least with code that is associated with the frame update process. In most use cases, filter logic like this will be used in that update process (which gets run many times a second).

That being said, I'm going to try and find an alternative fix for this issue. It should accept the same input and return the same output as your patch, so you should be able to continue using it until I figure out my own approach.

If I determine that a type check is unavoidable, I will merge your fork.

jeremyckahn commented 13 years ago

Alrighty, I found the root of the issue. I forgot to apply one of the filters that the color extension depends on. The way the interpolate extension works is by "faking" key parts of the tween creation process and then just returning the value, and I forgot a part of process. My bad!

The fix is here.

I had to add a line to interpolate, so the bug wasn't in color. The code structure is kinda complex, so I admit that the fix for this issue wasn't totally obvious. Thanks for finding bug! Closing this pull request.