Reproducing A Clever Animation Product, Part 23

Today I changed the form of specifying a tween effect. It was originally specified as a string (e.g., “linear” or “vibrate_right”) but now it is defined as an object literal. The first member field of the object has to be effect and its value specifies the effect to be used. If the effect requires additional parameters then those may also be provided within the object literal, but defaults are provided for all values so they aren’t strictly necessary.

Here is the code for the processEffect function I described yesterday. As noted in the comments it’s kind of annoying to have to peel the effect description objects apart every time this routine is called, but that can be improved later by creating some external state variables. Whether you as a developer would want to pursue that course of action is a matter of taste. Do you want more speed or to use less memory?

Now that this is in place it can (theoretically) be used to modify a wide variety of tweens. The code for each type of modification need only be written once.

Here’s the animation with a new block showing that the vibrate effect works as intended. There are a lot more twists I could put on this thing but the basics are working for now.

This entry was posted in Tools and methods and tagged , , . Bookmark the permalink.

Leave a Reply