UNPKG

duckengine

Version:
208 lines (207 loc) 6.17 kB
import { Duck } from '../..'; import Timer from '../../base/timer'; import Game from '../game'; import Sprite from '../gameobjects/sprite'; import Scene from '../scene'; import AnimationFrame from './animationFrame'; /** * @class Animation * @classdesc Creates a DuckEngine Animation * @description The Animation Class. An animation of frames that are used for Sprites * @since 2.0.0 */ export default class Animation { /** * @memberof Animation * @description A name/key for the Animation, used by AnimationManager to play the animation * @type string * @since 2.0.0 */ readonly key: string; /** * @memberof Animation * @description Configuration for the Animation, changing this has no effect, instead change the values of the Animation.<prop> * @type Duck.Types.Animation.Config * @since 2.0.0 */ config: Duck.Types.Animation.Config; /** * @memberof Animation * @description Game instance * @type Game * @since 2.0.0 */ game: Game; /** * @memberof Animation * @description Scene instance * @type Scene * @since 2.0.0 */ scene: Scene; /** * @memberof Animation * @description Sprite that the animation is attached to * @type Sprite * @since 2.0.0 */ sprite: Sprite; /** * @memberof Animation * @description What the internal timers count by, defaults to the game delta time so that it can be used in the Scene.update loop * @type number * @since 2.0.0 */ countBy: number; /** * @memberof Animation * @description The amount of times the animation repeats, modified from config so that it would work with the internal Timers * @type number * @since 2.0.0 */ repeat: number; /** * @memberof Animation * @description The current amount of times an animation played/repeated * @type number * @since 2.0.0 */ repeatCounter: number; /** * @memberof Animation * @description An array of AnimationFrames generated from Duck.Types.Animation.FrameBase array in config * @type AnimationFrame[] * @since 2.0.0 */ frames: AnimationFrame[]; /** * @memberof Animation * @description The same as Animation#AnimationFrames but reversed * @type AnimationFrame[]; * @since 2.0.0 */ reversedFrames: AnimationFrame[]; /** * @memberof Animation * @description An internal Timer that is used for counting and playing an AnimationFrame normally * @type Timer * @since 2.0.0 */ animationNormalTimer: Timer; /** * @memberof Animation * @description An internal Timer that is used for counting and playing an AnimationFrame reversely * @type Timer * @since 2.0.0 */ animationReverseTimer: Timer; /** * @memberof Animation * @description An internal Timer that is used for counting and delaying before playing the Animation, undefined * if Config.delay is not a number * @type Timer | undefined * @since 2.0.0 */ delayTimer: Timer | undefined; /** * @memberof Animation * @description The current index of the Animation#frames or Animation#reversedFrames * @type number * @since 2.0.0 */ currentIndex: number; /** * @memberof Animation * @description The current frame being played * @type AnimationFrame * @since 2.0.0 */ currentFrame: AnimationFrame; /** * @constructor Animation * @description Creates an Animation instance * @param {Duck.Types.Animation.Config} config Animation configuration * @param {Game} game Game instance * @param {Scene} scene Scene instance * @param {Sprite} sprite Sprite that the Animation is attached to * @since 2.0.0 */ constructor(config: Duck.Types.Animation.Config, game: Game, scene: Scene, sprite: Sprite); protected createFrames(): AnimationFrame[]; protected normalStep(self: Animation): void; protected reverseStep(self: Animation): void; /** * @memberof Animation * @description Sets the repeat amount of the internal normal timer * @param {number} repeat Repeat amount * @since 2.0.0 */ setRepeat(repeat: number): void; /** * @memberof Animation * @description Sets the repeat amount of the internal reverse timer * @param {number} repeat Repeat amount * @since 2.0.0 */ setRepeatReverse(repeat: number): void; /** * @memberof Animation * @description Plays the Animation using the internal normal timer * @since 2.0.0 */ play(): void; /** * @memberof Animation * @description Plays the Animation using the internal reverse timer * @since 2.0.0 */ playReverse(): void; /** * @memberof Animation * @description Pauses the Animation using the internal normal timer * @since 2.0.0 */ pause(): void; /** * @memberof Animation * @description Pauses the Animation using the internal reverse timer * @since 2.0.0 */ pauseReverse(): void; /** * @memberof Animation * @description REsumes the Animation using the internal normal timer * @since 2.0.0 */ resume(): void; /** * @memberof Animation * @description Resumes the Animation using the internal reverse timer * @since 2.0.0 */ resumeReverse(): void; /** * @memberof Animation * @description Stops/Cancels the Animation using the internal normal timer * @since 2.0.0 */ stop(): void; /** * @memberof Animation * @description Stops/Cancels the Animation using the internal reverse timer * @since 2.0.0 */ stopReverse(): void; /** * @memberof Animation * @description Restarts the Animation using the internal normal timer * @since 2.0.0 */ restart(): void; /** * @memberof Animation * @description Restarts the Animation using the internal reverse timer * @since 2.0.0 */ restartReverse(): void; }