starling-framework
Version:
A fast, productive library for 2D cross-platform development.
200 lines • 7.44 kB
TypeScript
import EventDispatcher from "../events/EventDispatcher";
import IAnimatable from "./IAnimatable";
declare namespace starling.animation {
/**
* A Tween animates numeric properties of objects. It uses different transition functions
* * to give the animations various styles.
* *
* * <p>The primary use of this class is to do standard animations like movement, fading,
* * rotation, etc. But there are no limits on what to animate; as long as the property you want
* * to animate is numeric (<code>int, uint, Number</code>), the tween can handle it. For a list
* * of available Transition types, look at the "Transitions" class.</p>
* *
* * <p>Here is an example of a tween that moves an object to the right, rotates it, and
* * fades it out:</p>
* *
* * <listing>
* * var tween:Tween = new Tween(object, 2.0, Transitions.EASE_IN_OUT);
* * tween.animate("x", object.x + 50);
* * tween.animate("rotation", deg2rad(45));
* * tween.fadeTo(0); // equivalent to 'animate("alpha", 0)'
* * Starling.juggler.add(tween);</listing>
* *
* * <p>Note that the object is added to a juggler at the end of this sample. That's because a
* * tween will only be executed if its "advanceTime" method is executed regularly - the
* * juggler will do that for you, and will remove the tween when it is finished.</p>
* *
* * @see Juggler
* * @see Transitions
*
*/
export class Tween extends EventDispatcher implements IAnimatable {
/**
* Creates a tween with a target, duration (in seconds) and a transition function.
* * @param target the object that you want to animate
* * @param time the duration of the Tween (in seconds)
* * @param transition can be either a String (e.g. one of the constants defined in the
* * Transitions class) or a function. Look up the 'Transitions' class for a
* * documentation about the required function signature.
*/
constructor(target: any, time: number, transition?: any);
/**
* Resets the tween to its default values. Useful for pooling tweens.
*/
reset(target: any, time: number, transition?: any): Tween;
/**
* Animates the property of the target to a certain value. You can call this method
* * multiple times on one tween.
* *
* * <p>Some property types are handled in a special way:</p>
* * <ul>
* * <li>If the property contains the string <code>color</code> or <code>Color</code>,
* * it will be treated as an unsigned integer with a color value
* * (e.g. <code>0xff0000</code> for red). Each color channel will be animated
* * individually.</li>
* * <li>The same happens if you append the string <code>#rgb</code> to the name.</li>
* * <li>If you append <code>#rad</code>, the property is treated as an angle in radians,
* * making sure it always uses the shortest possible arc for the rotation.</li>
* * <li>The string <code>#deg</code> does the same for angles in degrees.</li>
* * </ul>
*
*/
animate(property: string, endValue: number): void;
/**
* Animates the 'scaleX' and 'scaleY' properties of an object simultaneously.
*/
scaleTo(factor: number): void;
/**
* Animates the 'x' and 'y' properties of an object simultaneously.
*/
moveTo(x: number, y: number): void;
/**
* Animates the 'alpha' property of an object to a certain target value.
*/
fadeTo(alpha: number): void;
/**
* Animates the 'rotation' property of an object to a certain target value, using the
* * smallest possible arc. 'type' may be either 'rad' or 'deg', depending on the unit of
* * measurement.
*/
rotateTo(angle: number, type?: string): void;
/**
* @inheritDoc
*/
advanceTime(time: number): void;
/**
* The end value a certain property is animated to. Throws an ArgumentError if the
* * property is not being animated.
*/
getEndValue(property: string): number;
/**
* Indicates if a property with the given name is being animated by this tween.
*/
animatesProperty(property: string): boolean;
/**
* Indicates if the tween is finished.
*/
get isComplete(): boolean;
/**
* The target object that is animated.
*/
get target(): any;
/**
* The transition method used for the animation. @see Transitions
*/
get transition(): string;
set transition(value: string)
/**
* The actual transition function used for the animation.
*/
get transitionFunc(): (arg0: number) => number;
set transitionFunc(value: (arg0: number) => number)
/**
* The total time the tween will take per repetition (in seconds).
*/
get totalTime(): number;
/**
* The time that has passed since the tween was created (in seconds).
*/
get currentTime(): number;
/**
* The current progress between 0 and 1, as calculated by the transition function.
*/
get progress(): number;
/**
* The delay before the tween is started (in seconds). @default 0
*/
get delay(): number;
set delay(value: number)
/**
* The number of times the tween will be executed.
* * Set to '0' to tween indefinitely. @default 1
*/
get repeatCount(): number;
set repeatCount(value: number)
/**
* The amount of time to wait between repeat cycles (in seconds). @default 0
*/
get repeatDelay(): number;
set repeatDelay(value: number)
/**
* Indicates if the tween should be reversed when it is repeating. If enabled,
* * every second repetition will be reversed. @default false
*/
get reverse(): boolean;
set reverse(value: boolean)
/**
* Indicates if the numeric values should be cast to Integers. @default false
*/
get roundToInt(): boolean;
set roundToInt(value: boolean)
/**
* A function that will be called when the tween starts (after a possible delay).
*/
get onStart(): Function;
set onStart(value: Function)
/**
* A function that will be called each time the tween is advanced.
*/
get onUpdate(): Function;
set onUpdate(value: Function)
/**
* A function that will be called each time the tween finishes one repetition
* * (except the last, which will trigger 'onComplete').
*/
get onRepeat(): Function;
set onRepeat(value: Function)
/**
* A function that will be called when the tween is complete.
*/
get onComplete(): Function;
set onComplete(value: Function)
/**
* The arguments that will be passed to the 'onStart' function.
*/
get onStartArgs(): Array<any>;
set onStartArgs(value: Array<any>)
/**
* The arguments that will be passed to the 'onUpdate' function.
*/
get onUpdateArgs(): Array<any>;
set onUpdateArgs(value: Array<any>)
/**
* The arguments that will be passed to the 'onRepeat' function.
*/
get onRepeatArgs(): Array<any>;
set onRepeatArgs(value: Array<any>)
/**
* The arguments that will be passed to the 'onComplete' function.
*/
get onCompleteArgs(): Array<any>;
set onCompleteArgs(value: Array<any>)
/**
* Another tween that will be started (i.e. added to the same juggler) as soon as
* * this tween is completed.
*/
get nextTween(): Tween;
set nextTween(value: Tween)
}
}
export default starling.animation.Tween;