SamplePlugin Class
A sample TweenJS plugin. This plugin does not actually affect tweens in any way, it's merely intended to document how to build TweenJS plugins. Please look at the code for inline comments.
A TweenJS plugin is simply an object that exposes one property (priority), and three methods (init, step, and tween).
Generally a plugin will also expose an install method as well, though this is not strictly necessary.
Constructor
SamplePlugin
()
Methods
init
-
tween -
prop -
value
Called by TweenJS when a new tween property initializes that this plugin is registered for. Generally, the call
to Plugin.init will be immediately followed by a call to Plugin.to.
Parameters:
Returns:
The starting tween value for the property. In most cases, you would simply return the value parameter, but some plugins may need to modify the starting value.
init
-
tween -
prop -
startValue -
injectProps -
endValue
Called by TweenJS when a new step is added to a tween that includes a property the plugin is registered for (ie. a new "to" action is added to a tween).
Parameters:
-
tweenTweenThe related tween instance.
-
propStringThe name of the property being tweened.
-
startValueAnyThe value of the property at the beginning of the step. This will be the same as the init value if this is the first step, or the same as the endValue of the previous step if not.
-
injectPropsObjectA generic object to which the plugin can append other properties which should be updated on this step.
-
endValueAnyThe value of the property at the end of the step.
install
()
static
Installs this plugin for use with TweenJS, and registers for a list of properties that this plugin will operate with. Call this once after TweenJS is loaded to enable this plugin.
tween
-
tween -
prop -
value -
startValues -
endValues -
ratio -
wait -
end
Called when a tween property advances that this plugin is registered for.
Parameters:
-
tweenTweenThe related tween instance.
-
propStringThe name of the property being tweened.
-
valueAnyThe current tweened value of the property, as calculated by TweenJS.
-
startValuesObjectA hash of all of the property values at the start of the current step. You could access the start value of the current property using startValues[prop].
-
endValuesObjectA hash of all of the property values at the end of the current step.
-
ratioNumberA value indicating the eased progress through the current step. This number is generally between 0 and 1, though some eases will generate values outside this range.
-
waitBooleanIndicates whether the current step is a "wait" step.
-
endBooleanIndicates that the tween has reached the end.
Returns:
Return the value that should be assigned to the target property. For example
returning Math.round(value) would assign the default calculated value
as an integer. Returning Tween.IGNORE will prevent Tween from assigning a value to
the target property.
Properties
priority
Unknown
static
Used by TweenJS to determine when to call this plugin. Plugins with higher priority have their methods called before plugins with lower priority. The priority value can be any positive or negative number.