UNPKG

@puxi/tween

Version:

PixiJS tweening library

10 lines (9 loc) 2.89 kB
/*! * @puxi/tween - v1.0.0 * Compiled Sun, 22 Mar 2020 22:05:27 UTC * * @puxi/tween is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */ this.PUXI=this.PUXI||{},this.PUXI.tween=this.PUXI.tween||{};var _puxi_tween=function(e,t){"use strict";class s extends t.utils.EventEmitter{constructor(e,t,s,i,n,r,a,h,o,u=1,p=!0){super(),this.manager=e,this.key=t,this.startValue=s,this.endValue=i,this.erp=n,this.ease=r,this.observedValue=a,this.startTime=h,this.endTime=o,this._repeat=u,this._flip=p,this._next=null,this._target=null,this._observedProperty=null,this.autoCreated=!1}update(e=performance.now()){if(e=(e-this.startTime)/(this.endTime-this.startTime),e=Math.min(Math.max(e,0),1),this.ease&&(e=this.ease(e)),this.observedValue=this.erp(this.startValue,this.endValue,Math.min(Math.max(e,0),1),this.observedValue),this.emit("update",this.observedValue,this.key),this._target&&(this._target[this._observedProperty]=this.observedValue),e>=1){if(--this._repeat,this.emit("cycle",this),this._repeat>0){if(this._flip){const{startValue:e,endValue:t}=this;this.endValue=e,this.startValue=t}const e=this.endTime-this.startTime;return this.startTime+=e,void(this.endTime+=e)}this._next&&this.manager.queue(this._next),this.reset(),this.emit("complete",this),this.removeAllListeners()}}target(e,t){return this._target=e,this._observedProperty=t,this}repeat(e,t=!0){return this._repeat=e,this._flip=t,this}chain(e,t,i,n,r){const a=s.pool.pop()||new s;return a.manager=this.manager,a.key=0,a.startValue=e,a.endValue=t,a.startTime=this.endTime,a.endTime=a.startTime+i,a.erp=n,a.ease=r,this._next=a,a}reset(){this.ease=null,this._repeat=0,this._next=null,this._target=null,this._observedProperty=null}destroy(){this.reset(),this.autoCreated&&s.pool.push(this)}}s.pool=[],e.nextTweenKey=0;return e.EaseBoth=e=>e<=.5?2*e*e:(e-.5)*(1.5-e)*2+.5,e.EaseIn=e=>e*e,e.EaseOut=e=>(1-e)*(1-e),e.NumberErp=(e,t,s)=>(1-s)*e+s*t,e.PointErp=(e,s,i,n)=>(n||(n=new t.Point),n.x=(1-i)*e.x+i*s.x,n.y=(1-i)*e.y+i*s.y,n),e.Tween=s,e.TweenManager=class{constructor(e=!0){this.onUpdate=()=>{for(const[,e]of this.tweenMap)e.update()},this.onTweenComplete=e=>{this.tweenMap.delete(e.key),e.destroy()},this.tweenMap=new Map,e&&this.start()}tween(t,i,n,r,a){const h=s.pool.pop()||new s;return h.autoCreated=!0,h.reset(),h.manager=this,h.key=e.nextTweenKey++,h.startValue=t,h.endValue=i,h.erp=r,h.ease=a,h.startTime=performance.now(),h.endTime=h.startTime+n,this.tweenMap.set(h.key,h),h.on("complete",this.onTweenComplete),h}queue(t){return t.key=e.nextTweenKey++,this.tweenMap.set(t.key,t),t.on("complete",this.onTweenComplete),this}start(){this.isRunning||(t.Ticker.shared.add(this.onUpdate),this.isRunning=!0)}stop(){this.isRunning&&(t.Ticker.shared.remove(this.onUpdate),this.isRunning=!1)}},e}({},PIXI);Object.assign(this.PUXI.tween,_puxi_tween); //# sourceMappingURL=puxi-tween.min.js.map