UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

121 lines (106 loc) 4.28 kB
// Class: starling.animation.DelayedCall var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; var $extend = require("./../../extend_stub").default; function starling_animation_IAnimatable() {return require("./../../starling/animation/IAnimatable");} function starling_events_EventDispatcher() {return require("./../../starling/events/EventDispatcher");} function Reflect() {return require("./../../Reflect");} function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");} // Constructor var DelayedCall = function(callback,delay,args) { (starling_events_EventDispatcher().default).call(this); this.reset(callback,delay,args); } // Meta DelayedCall.__name__ = "starling.animation.DelayedCall"; DelayedCall.__isInterface__ = false; DelayedCall.__interfaces__ = [(starling_animation_IAnimatable().default)]; DelayedCall.__super__ = (starling_events_EventDispatcher().default); DelayedCall.prototype = $extend((starling_events_EventDispatcher().default).prototype, { reset: function(callback,delay,args) { this.__currentTime = 0; this.__totalTime = Math.max(delay,0.0001); this.__callback = callback; this.__args = args != null ? args : []; this.__repeatCount = 1; return this; }, advanceTime: function(time) { var previousTime = this.__currentTime; this.__currentTime += time; if(this.__currentTime > this.__totalTime) { this.__currentTime = this.__totalTime; } if(previousTime < this.__totalTime && this.__currentTime >= this.__totalTime) { if(this.__repeatCount == 0 || this.__repeatCount > 1) { (Reflect().default).callMethod(this.__callback,this.__callback,this.__args); if(this.__repeatCount > 0) { this.__repeatCount -= 1; } this.__currentTime = 0; this.advanceTime(previousTime + time - this.__totalTime); } else { var call = this.__callback; var args = this.__args; this.dispatchEventWith("removeFromJuggler"); (Reflect().default).callMethod(call,call,args); } } }, complete: function() { var restTime = this.__totalTime - this.__currentTime; if(restTime > 0) { this.advanceTime(restTime); } }, get_isComplete: function() { if(this.__repeatCount == 1) { return this.__currentTime >= this.__totalTime; } else { return false; } }, get_totalTime: function() { return this.__totalTime; }, get_currentTime: function() { return this.__currentTime; }, get_repeatCount: function() { return this.__repeatCount; }, set_repeatCount: function(value) { return this.__repeatCount = value; }, get_callback: function() { return this.__callback; }, get_arguments: function() { return this.__args; } }); DelayedCall.prototype.__class__ = DelayedCall.prototype.constructor = $hxClasses["starling.animation.DelayedCall"] = DelayedCall; // Init Object.defineProperties(DelayedCall.prototype,{ isComplete : { get : function () { return this.get_alpha (); }}, totalTime : { get : function () { return this.get_totalTime (); }}, currentTime : { get : function () { return this.get_currentTime (); }}, repeatCount : { get : function () { return this.get_repeatCount (); }, set : function (v) { return this.set_repeatCount (v); }}, callback : { get : function () { return this.get_callback (); }}, 'arguments' : { get : function () { return this.get_arguments (); }}}); // Statics DelayedCall.fromPool = function(call,delay,args) { if(DelayedCall.sPool.length != 0) { return (openfl__$Vector_Vector_$Impl_$().default).pop(DelayedCall.sPool).reset(call,delay,args); } else { return new DelayedCall(call,delay,args); } } DelayedCall.toPool = function(delayedCall) { delayedCall.__callback = null; delayedCall.__args = null; delayedCall.removeEventListeners(); (openfl__$Vector_Vector_$Impl_$().default).push(DelayedCall.sPool,delayedCall); } DelayedCall.sPool = (openfl__$Vector_Vector_$Impl_$().default)._new() // Export exports.default = DelayedCall;