API Documentation for: 1.0.0
Show:

SamplePlugin Class

Defined in: SamplePlugin:39
Module: TweenJS

A sample TweenJS plugin. This plugin is purely for demonstration, and contains documentation and helpful tips on building plugins.

It sets the y position of the target based on a sinusoidal function of its x position.

NOTE: The code for this class is heavily commented. Please look at it if you'd like to write a plugin.

A TweenJS plugin is simply an object that exposes two properties (id, priority), and three methods (init, step, and change). Generally a plugin will also expose an install method as well, though this is not strictly necessary.

Constructor

SamplePlugin

()

Defined in SamplePlugin:39

Item Index

Methods

Properties

Methods

change

(
  • tween
  • step
  • prop
  • value
  • ratio
  • end
)
Any static

Defined in change:203

Called before a property is updated by the tween.

Parameters:

  • tween Tween

    The related tween instance.

  • step TweenStep

    The related tween step. This class is currently undocumented. See the bottom of Tween.js for info.

  • prop String

    The name of the property being tweened.

  • value Any

    The current tweened value of the property, as calculated by TweenJS. Previous plugins may have modified this value.

  • ratio Number

    A 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.

  • end Boolean

    Indicates that the tween has reached the end and is about to deregister itself.

Returns:

Any:

Return the value that should be assigned to the target property.

init

(
  • tween
  • prop
  • value
)
Any static

Defined in init:93

Called by TweenJS when a new property initializes on a tween. Generally, the call to Plugin.init will be immediately followed by a call to Plugin.step.

For example:

foo.x = 0;
foo.y = 100;
Tween.get(foo)
    .to({x:10}) // init called with prop = "x", value = 0
    .to({x:20}) // init is NOT called, since x was already inited
    .to({y:200}) // init called with prop = "y", value = 100

Parameters:

  • tween Tween

    The related tween instance.

  • prop String

    The name of the property that is being initialized.

  • value Any

    If another plugin has modified the starting value, it will be passed in. Otherwise value will be undefined.

Returns:

Any:

The modified starting tween value for the property. In most cases, you would simply wouldn't return anything, but some plugins may need to modify the starting value. You can also return Tween.IGNORE to prevent this prop from being added to the tween at all.

install

() static

Defined in install:83

Installs this plugin for use with TweenJS. Call this once after TweenJS is loaded to enable this plugin.

step

(
  • tween
  • step
  • props
)
static

Defined in step:157

Called when a new step is added to a tween (ie. a new "to" action is added to a tween).

For example: Tween.get(foo) .to({x:10}) // step called .wait(100) // step is NOT called .to({x:20, y:200}) // step called

Parameters:

  • tween Tween

    The related tween instance.

  • step TweenStep

    The related tween step. This class is currently undocumented. See the bottom of Tween.js for info.

  • props Object

    The props object that was passed to to().

Properties

ID

String static readonly

Defined in ID:71

READ-ONLY. A unique identifying string for this plugin. Used by TweenJS to ensure duplicate plugins are not installed on a tween.

priority

Number static

Defined in priority:58

Used by TweenJS to determine when to call this plugin relative to others. Plugins with higher priority read first, and write last.

For example, if plugin A has priority=0, and plugin B has priority=9 then B's init and step methods would be called before A's, but B's change method would be called after A's.

Default: 0