min-as
Version:
MinAs 是一个运行在微信小程序的JavaScript 库,仅仅10几kb左右,旨在让开发者能像使用 pixijs和Flash AS3 一样,在微信小程序的 Canvas 中优雅地使用精灵Sprite、补简动画Tween、逐帧动画精灵AnimatedSprite。同样也特别适合那些想在微信小程序中开发小游戏功能的项目,又或者你想做个游戏界面风格的应用小程序。
2 lines (1 loc) • 19.9 kB
JavaScript
"use strict";var H=Object.defineProperty;var k=(n,t,e)=>t in n?H(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var a=(n,t,e)=>k(n,typeof t!="symbol"?t+"":t,e);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});function M(n){return n*180/Math.PI}function S(n){return M(Math.atan2(n[1][1]-n[0][1],n[1][0]-n[0][0]))}function P(n){return Math.sqrt(Math.pow(n[1][0]-n[0][0],2)+Math.pow(n[1][1]-n[0][1],2))}function C(n){return n/180*Math.PI}function W(n,t,e){const i=C(t||0);return E(n,i)}function E(n,t){return[n[0]*Math.cos(t)-n[1]*Math.sin(t),n[0]*Math.sin(t)+n[1]*Math.cos(t)]}function T(n,t=0,e=0){const i=C(t);return[n[0]+e*Math.cos(i),n[1]+e*Math.sin(i)]}function I(n){if(n.length<3)return null;let t=1/0,e=-1/0,i=1/0,s=-1/0,h=!1;for(let r=0,c=n.length;r<c;r++){const o=n[r],l=o[0],u=o[1];l!=null&&isFinite(l)&&u!=null&&isFinite(u)&&(h=!0,l<t&&(t=l),l>e&&(e=l),u<i&&(i=u),u>s&&(s=u))}return h?[[t,i],[e,s]]:null}function b(n){let t=0,e=0,i=0,s=n.length;for(let r=0;r<s;r++){const c=r===s-1?0:r+1,o=n[r],l=n[c],u=o[0]*l[1]-l[0]*o[1];t+=u,e+=(o[0]+l[0])*u,i+=(o[1]+l[1])*u}const h=t*3;return[e/h,i/h]}function O(n,t,e){let i=[];for(let s=0,h=n.length;s<h;s++)i[s]=W(n[s],t);return i}function D(n,t,e){e||(e=b(n));let i=[];for(let s=0,h=n.length;s<h;s++){const r=n[s],c=P([e,r]),o=S([e,r]);i[s]=T(e,o,c*t)}return i}function F(n,t,e){e||(e=b(n));let i=[];for(let s=0,h=n.length;s<h;s++){const r=n[s],c=P([e,r]),o=S([e,r]),l=T(e,o,c*t);i[s]=[l[0],r[1]]}return i}function U(n,t,e){e||(e=b(n));let i=[];for(let s=0,h=n.length;s<h;s++){const r=n[s],c=P([e,r]),o=S([e,r]),l=T(e,o,c*t);i[s]=[r[0],l[1]]}return i}function j(n,t){let e=n[0],i=n[1],s=!1;for(let h=0,r=t.length-1;h<t.length;r=h++){const c=t[h][0],o=t[h][1],l=t[r][0],u=t[r][1];o>i!=u>i&&e<(l-c)*(i-o)/(u-o)+c&&(s=!s)}return s}function f(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){const t=Math.random()*16|0;return(n==="x"?t:t&3|8).toString(16)})}class m{constructor(t={}){a(this,"_children",[]);a(this,"isStart",!1);a(this,"x",0);a(this,"y",0);a(this,"px",0);a(this,"py",0);a(this,"width",0);a(this,"height",0);a(this,"texture",null);a(this,"backgroundColor","");a(this,"scaleX",1);a(this,"scaleY",1);a(this,"pScaleX",1);a(this,"pSscaleY",1);a(this,"angle",0);a(this,"pAngle",0);a(this,"opacity",1);a(this,"pOpacity",1);a(this,"visible",!0);a(this,"pVisible",!0);a(this,"hotPolygon",[]);a(this,"changeHotPolygon",[]);a(this,"hotPolygonColor","");a(this,"showHotPolygon",!1);a(this,"pointerEvents",!0);a(this,"_events",{touchstart:"",touchmove:"",touchend:"",touchcancel:""});a(this,"_isListen",!1);a(this,"_isBindEvent",!1);a(this,"_minAs",null);a(this,"canvas",null);a(this,"ctx",null);a(this,"_parent",null);a(this,"graphics",null);a(this,"type","Sprite");this.parentId="",this.id=t.id?t.id:f(),this.name=t.name?t.name:f(),this.x=t.x?t.x:0,this.y=t.y?t.y:0,this.width=t.width?t.width:0,this.height=t.height?t.height:0,this.backgroundColor=t.backgroundColor?t.backgroundColor:"",this.scaleX=t.scaleX!=null?t.scaleX:1,this.scaleY=t.scaleY!=null?t.scaleY:1,this.angle=t.angle?t.angle:0,this.opacity=t.opacity!==void 0?t.opacity:1,this.visible=t.visible!==void 0?t.visible:!0,this.onDraw=t.onDraw?t.onDraw:null,this.hotPolygon=Array.isArray(t.hotPolygon)?t.hotPolygon:[],this.showHotPolygon=t.showHotPolygon!==void 0?t.showHotPolygon:!1,this.hotPolygonColor=t.hotPolygonColor?t.hotPolygonColor:"#000000"}start(t={}){this.canvas=t.canvas,this.ctx=t.ctx,this._minAs=t._minAs,t._parent&&(this._parent=t._parent),this.isStart=!0,this.screenWidth=t.screenWidth,this.screenHeight=t.screenHeight}draw(){this._isListen&&this._isBindEvent===!1&&(this._initEvent(),this._isBindEvent=!0),this._getVisible()!==!1&&(this.isStart&&(this._drawBackground(),this.onDraw&&typeof this.onDraw=="function"&&this.onDraw(this)),this._drawChild())}appendChild(t){if(t.type=="Layer"){console.warn("子元素不能为图层Layer类型!");return}this._children.push(t)}removeChild(t){t.isStart=!1,t._removeEvent(),this._children.forEach((e,i)=>{if(e.id===t.id)return this._children.splice(i,1),i})}removeAll(){this._children.forEach(t=>{t.isStart=!1,t._removeEvent()}),this._children=[]}removeFromParent(){this._parent&&this._parent.removeChild(this)}on(t,e){this._events[t]!==void 0&&(this._isListen=!0,this._events[t]=e)}setIndex(t){const e=this._parent._children.indexOf(this);if(e!==-1){const i=this._parent._children,s=i.length-1;if(t<0&&(t=0),t>s&&(t=s),e===t)return;i.splice(e,1),i.splice(t,0,this)}}getIndex(){return this._parent._children.indexOf(this)}toFront(){const t=this._parent._children.indexOf(this);t!==-1&&(this._parent._children.splice(t,1),this._parent._children.push(this))}toBack(){const t=this._parent._children.indexOf(this);t!==-1&&(this._parent._children.splice(t,1),this._parent._children.unshift(this))}destroy(){this.removeFromParent()}_initEvent(){for(let t in this._events)this._minAs.on(t,e=>{if(this._getVisible()!==!1&&typeof this._events[t]=="function"){let i=null;if(e.touches&&e.touches.length===1)i=e.touches[0];else if(e.changedTouches&&e.changedTouches.length===1)i=e.changedTouches[0];else return;const s=i.clientX,h=i.clientY;this._isCollisionDetected(s,h)&&this._events[t](e)}})}_removeEvent(){this._events={touchstart:"",touchmove:"",touchend:"",touchcancel:""}}_drawBackground(){const t=this._getX(),e=this._getY(),i=this._getOpacity(),s=this._getScaleX(),h=this._getScaleY(),r=this._getAngle();this.hotPolygon.length===0&&(this.hotPolygon=[[0,0],[0,this.height],[this.width,this.height],[this.width,0]]);let c=JSON.parse(JSON.stringify(this.hotPolygon));r!==0&&(c=O(c,r)),s!==1&&h!==1&&s===h?c=D(this.hotPolygon,s,[0,0]):(s!==1&&(c=F(this.hotPolygon,s,[0,0])),h!==1&&(c=U(c,h,[0,0]))),this.changeHotPolygon=c.map(l=>[l[0]+t,l[1]+e]),this.ctx.save(),this.ctx.globalAlpha=i,this.ctx.translate(t,e),this.ctx.scale(s,h);const o=this._getAngle()*(Math.PI/180);this.ctx.rotate(o),this.ctx.translate(-t,-e),this.backgroundColor&&(this.ctx.fillStyle=this.backgroundColor,this.ctx.fillRect(t,e,this.width,this.height)),this.texture&&(this.width===0&&this.height===0?this.ctx.drawImage(this.texture,t,e):this.ctx.drawImage(this.texture,t,e,this.width,this.height));for(let l=0;l<this._children.length;l++){const u=this._children[l];u.type=="Shape"&&this.ctx.drawImage(u.offscreenCanvas,t+u.x,e+u.y,u.width,u.height)}if(this.ctx.restore(),this.showHotPolygon!==!1){this.ctx.save(),this.ctx.strokeStyle=this.hotPolygonColor,this.ctx.lineWidth=1,this.ctx.beginPath();for(let l=0;l<this.changeHotPolygon.length;l++){const u=this.changeHotPolygon[l];l===0?this.ctx.moveTo(u[0],u[1]):this.ctx.lineTo(u[0],u[1])}this.ctx.closePath(),this.ctx.stroke(),this.ctx.restore()}}_drawChild(){for(let t=0;t<this._children.length;t++){const e=this._children[t];e.type!="Shape"&&(e.isStart===!1&&this.canvas&&e.start({canvas:this.canvas,ctx:this.ctx,_parent:this,_minAs:this._minAs}),e.draw())}}_isCollisionDetected(t,e){if(!j([t,e],this.changeHotPolygon))return!1;if(this._parent){const h=this._parent._children,r=h.indexOf(this);for(let c=h.length-1;c>r;c--){const o=h[c];if(o.pointerEvents&&o._isCollisionDetected(t,e))return!1}}let s=this._parent;for(;s;){if(s._parent){const h=s._parent._children;if(h.length>1){const r=h.indexOf(s);for(let c=h.length-1;c>r;c--){const o=h[c];if(o.pointerEvents&&o._isCollisionDetected(t,e))return!1}}}s=s._parent}return!0}_getX(){return this.px=this._parent?this._parent._getX():0,this.x+this.px}_getY(){return this.py=this._parent?this._parent._getY():0,this.y+this.py}_getScaleX(){return this.pScaleX=this._parent?this._parent._getScaleX():1,this.scaleX*this.pScaleX}_getScaleY(){return this.pScaleY=this._parent?this._parent._getScaleY():1,this.scaleY*this.pScaleY}_getAngle(){return this.pAngle=this._parent?this._parent._getAngle():0,this.angle+this.pAngle}_getOpacity(){return this.pOpacity=this._parent?this._parent._getOpacity():1,this.opacity*this.pOpacity}_getVisible(){return this.pVisible=this._parent?this._parent._getVisible():!0,this.visible&&this.pVisible}}class w extends m{constructor(t){super(t),this.type="Layer",this.pointerEvents=!1}appendChild(t){this._children.push(t)}draw(){super.draw()}updateWH(){const t=[];function e(r){for(let c=0;c<r.length;c++){const o=r[c];t.push(...o.changeHotPolygon),o._children&&o._children.length>0&&e(o._children)}}e(this._children);const i=I([...t]),s=Math.abs(i[0][0]-i[1][0])+i[0][0],h=Math.abs(i[0][1]-i[1][1])+i[0][1];this.width=s>this.screenWidth?s:this.screenWidth,this.height=h>this.screenHeight?h:this.screenHeight,this.showHotPolygon=!0,this.hotPolygon=[]}}class y{constructor(t,e={}){this._minAs=t,this._options=e,this.canvas=t.options.canvas,this.screenWidth=t.options.screenWidth?t.options.screenWidth:this.canvas.width,this.screenHeight=t.options.screenHeight?t.options.screenHeight:this.canvas.height}destroy(){console.log(this.pluginName,"插件销毁")}}a(y,"pluginName",""),a(y,"apis",[]);class v extends y{constructor(e){super(e);a(this,"stage",null);a(this,"camera",null);a(this,"_roleLayer",null);a(this,"_lookAtSprite",null);a(this,"_lookAtPoint",null);a(this,"_lookAtOffset",[0,0]);this.ctx=this.canvas.getContext("2d"),this.init()}init(){this.camera={x:0,y:0,width:this.screenWidth,height:this.screenHeight},this.stage=new w({id:"stage",x:0,y:0,screenWidth:this.screenWidth,screenHeight:this.screenHeight,width:this.screenWidth,height:this.screenHeight}),this.stage.start({canvas:this.canvas,ctx:this.ctx,_minAs:this._minAs,screenWidth:this.screenWidth,screenHeight:this.screenHeight}),this._minAs.stage=this.stage,this._roleLayer=new w({id:"stageRoleLayer",x:0,y:0,screenWidth:this.screenWidth,screenHeight:this.screenHeight,width:this.screenWidth,height:this.screenHeight}),this.appendChild(this._roleLayer)}renderCamera(){const e=this._roleLayer.width>this.screenWidth?this._roleLayer.width:this.screenWidth,i=this._roleLayer.height>this.screenHeight?this._roleLayer.height:this.screenHeight,s=()=>{this.camera.x-=this._lookAtOffset[0],this.camera.y-=this._lookAtOffset[1],this.camera.x<0&&(this.camera.x=0),this.camera.x>e-this.screenWidth&&(this.camera.x=e-this.screenWidth),this.camera.y<0&&(this.camera.y=0),this.camera.y>i-this.screenHeight&&(this.camera.y=i-this.screenHeight)};if(this._lookAtSprite){const h={x:this._lookAtSprite._getX()-this._roleLayer.x,y:this._lookAtSprite._getY()-this._roleLayer.y,w:this._lookAtSprite.width,h:this._lookAtSprite.height};this.camera.x=h.x-(this.screenWidth-h.w)/2,this.camera.y=h.y-(this.screenHeight-h.h)/2,s(),this._roleLayer.x=-this.camera.x,this._roleLayer.y=-this.camera.y}else this._lookAtPoint&&(this.camera.x=this._lookAtPoint[0]-this.screenWidth/2,this.camera.y=this._lookAtPoint[1]-this.screenHeight/2,s(),this._roleLayer.x=-this.camera.x,this._roleLayer.y=-this.camera.y)}render(e){this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.renderCamera();const i=this.stage._children;for(let s=0;s<i.length;s++)i[s].draw();this._minAs.transitionUpdate&&this._minAs.transitionUpdate(),this.mainTimer=this.canvas.requestAnimationFrame(()=>{e&&e(),this.render()})}appendChild(e){e instanceof w?(e.start({canvas:this.canvas,ctx:this.ctx,_minAs:this._minAs,_parent:this.stage,screenWidth:this.screenWidth,screenHeight:this.screenHeight}),e.parentId="stage",this.stage.appendChild(e)):e instanceof m&&(e.start({camera:this.camera,canvas:this.canvas,ctx:this.ctx,_minAs:this._minAs,_parent:this._roleLayer,screenWidth:this.screenWidth,screenHeight:this.screenHeight}),e.parentId="stageRoleLayer",this._roleLayer.appendChild(e))}removeChild(e){this.stage.removeChild(e)}removeAll(){this.stage.removeAll()}setRoleLayer(e={}){e.width!==void 0&&(this._roleLayer.width=e.width),e.height!==void 0&&(this._roleLayer.height=e.height),e.x!==void 0&&(this._roleLayer.x=e.x),e.y!==void 0&&(this._roleLayer.y=e.y)}getRoleLayer(){return this._roleLayer}lookAt(e,i=[0,0]){if(e==null){this._lookAtSprite=null,this._lookAtPoint=null,this._lookAtOffset=[0,0];return}Array.isArray(i)&&i.length===2&&(this._lookAtOffset=[...i]),e instanceof m?(this._lookAtPoint=null,this._lookAtSprite=e):Array.isArray(e)&&e.length===2&&(this._lookAtSprite=null,this._lookAtPoint=[...e])}destroy(){this.mainTimer&&(this.canvas.cancelAnimationFrame(this.mainTimer),this.mainTimer=null,this._minAs.tweenStop&&this._minAs.tweenStop(),this.removeAll(),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height))}}a(v,"pluginName","CanvasPlugin"),a(v,"events",[]),a(v,"apis",["render","appendChild","removeChild","removeAll","lookAt","setRoleLayer","getRoleLayer"]);class R{constructor(t){a(this,"Quadratic",{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)},Linear:function(t){return t}});this.id=f(),this.sprite=t,this.params={},this.beforeParams={},this.duration=1e3,this.timing="Linear",this.curTime=0,this.startTime=0,this.endTime=0,this.onplay=!1,this._isPlaying=!0,this.pauseTime=0}pause(){this.pauseTime=this.curTime,this._isPlaying=!1}resume(){const t=+new Date-this.pauseTime;this.startTime+=t,this.endTime+=t,this._isPlaying=!0}stop(){}_to(t={},e=1e3,i="Linear"){this.params=t,this.beforeParams={},this.duration=e,this.timing=i,this.curTime=0,this.startTime=0,this.endTime=0,this.onplay=!1;for(let s in this.sprite)typeof this.params[s]<"u"&&(this.beforeParams[s]=this.sprite[s])}_update(){if(this._isPlaying===!1)return;this.onplay?this.curTime=+new Date:(this.startTime=+new Date,this.endTime=this.startTime+this.duration,this.curTime=this.startTime,this.onplay=!0);let t=Math.min(1,Math.max(0,(this.curTime>=this.endTime?this.duration:this.curTime-this.startTime)/this.duration));if(!this.Quadratic[this.timing])return;let e=this.Quadratic[this.timing](t);for(let s in this.params)typeof this.sprite[s]<"u"&&(this.sprite[s]=this.beforeParams[s]+(this.params[s]-this.beforeParams[s])*e);typeof this.params.onUpdate=="function"&&this.params.onUpdate(this.sprite);let i=!1;if(t==1){if(this.onplay=!1,typeof this.params.onEnd=="function")try{this.params.onEnd(this.sprite)}catch{}i=!0}return i}}class A extends y{constructor(t,e={}){super(t,e),this.updateList=[]}transition(t,e){const i=e.duration*1e3||1e3,s=e.timing||"Linear",h={};for(let c in e)c!=="duration"&&c!=="timing"&&(h[c]=e[c]);let r=new R(t);return r.stop=()=>{const c=this.updateList.indexOf(r);c>-1&&(this.updateList.splice(c,1),r=null)},r._to(h,i,s),this.updateList.push(r),r}transitionList(t,e,i={}){const s=i.loop!==void 0?i.loop:!0,h=i.onEnd||(()=>{}),r=i.onUpdate||(()=>{}),c=i.onChange||(()=>{});let o=!1,l=[];const u=(d=0)=>{if(o)return;if(d>=e.length)if(s)d=0,l=[];else{h(t);return}const g=this.transition(t,{...e[d],onEnd:p=>{c(p,d),u(d+1)},onUpdate:p=>{r(p)}});this.index=d,l.push(g)};return u(),{stop:()=>{o=!0,l.forEach(d=>{d.stop()}),l=[]},pause:()=>{l[this.index]&&(o=!0,l[this.index].pause())},resume:()=>{l[this.index]&&(o=!1,l[this.index].resume())}}}transitionClean(){this.updateList=[]}transitionUpdate(){if(this.updateList.length>0)for(let t=this.updateList.length-1;t>=0;t--)this.updateList[t]._update()&&this.updateList.splice(t,1)}}a(A,"pluginName","TweenPlugin"),a(A,"apis",["transition","transitionList","transitionUpdate"]);class L extends y{constructor(e,i={}){super(e,i);a(this,"assets",{})}async assetsLoad(e="",i=null){const s=(h,r)=>{let c=null;typeof h=="object"&&h.url&&(h.metaImage&&(c=h.metaImage),h=h.url);const o=this._getResourceType(h);return o?new Promise((l,u)=>{if(o=="image"){let d=this.canvas.createImage();d.onload=()=>{this.assets[r]=d,l(r)},d.onerror=u,d.src=h}else o=="json"&&wx.request({url:h,header:{"content-type":"application/json"},success:d=>{const g=d.data,p=g.meta;let _=c;_||(_=p.image,/^https?:\/\//i.test(_)||(_=this._baseUrl(h)+p.image)),s(_,f()).then(async x=>{g.meta.image=this.assets[x],await this._anSplitImage(g),this.assets[r]=g,l(r)}).catch(x=>{u(x)})},fail(d){u(d)}})}):new Promise((l,u)=>{u(new Error(`类型不支持: ${h}`))})};if(typeof e=="string"){let h="";try{h=f(),await s(e,h)}catch(r){console.error(r)}return i&&i(100,h),h}else if(typeof e=="object"){let h=[],r=0;for(let c in e){try{await s(e[c],c),h.push(c)}catch(o){console.error(o)}if(i){const o=Math.floor((r+1)/e.length*100);i(o,c)}r++}return h}}getAssets(e=""){return e&&this.assets[e]?this.assets[e]:this.assets}_getResourceType(e){const i=/\.(png|jpg|jpeg|webp|bmp)$/i,s=/\.(json|js)$/i;return i.test(e)?"image":s.test(e)?"json":null}_baseUrl(e){const i=e.split("/");return i.pop(),i.join("/")+"/"}async _anSplitImage(e){const i=e.meta.image;try{for(let s in e.frames){const h=e.frames[s],r=h.frame,c=wx.createOffscreenCanvas({type:"2d",width:r.w,height:r.h});c.getContext("2d").drawImage(i,r.x,r.y,r.w,r.h,0,0,r.w,r.h);const l=c.toDataURL("image/png"),u=c.createImage();u.src=l,h.image=u}}catch(s){console.error(s)}}}a(L,"pluginName","AssetsPlugin"),a(L,"apis",["assetsLoad","getAssets"]);class X{constructor(){a(this,"pluginMap",{});a(this,"customApis",[]);a(this,"options",{});a(this,"events",{})}init(t={}){this.options=t,this._initDefPlugin(),console.log("min-as:v1.0.0","git:https://gitee.com/wugemianfei/min-as","website:https://qianqianquege.com/dream")}use(t,e){if(this._checkPlugin(t)){this._saveCustomAttr(t);const i=new t(this,e);i.pluginName=t.pluginName,this.pluginMap[t.pluginName]=i,this._bindingApis(i)}return this}destroy(){this.events={},this._pluginDestory()}_pluginDestory(){for(const t in this.pluginMap)this.pluginMap[t]&&this.pluginMap[t].destroy()}_initDefPlugin(){this.use(A),this.use(v),this.use(L)}_checkPlugin(t){const{pluginName:e,apis:i=[]}=t;if(this.pluginMap[e])throw new Error(e+"插件已存在");return i.forEach(s=>{if(this.customApis.find(h=>h===s))throw new Error(e+"插件中"+s+"方法已存在")}),!0}_saveCustomAttr(t){const{apis:e=[]}=t;this.customApis=this.customApis.concat(e)}_bindingApis(t){const{apis:e=[]}=t.constructor||{};e.forEach(i=>{this[i]=function(){return t[i].apply(t,[...arguments])}})}dispatchEvent(t){this.emit(t.type,t)}on(t,e){this.events[t]||(this.events[t]=[]),this.events[t].push(e)}emit(t,...e){this.events[t]&&this.events[t].forEach(i=>i(...e))}off(t,e){this.events[t]&&(this.events[t]=this.events[t].filter(i=>i!==e))}}class Y{constructor(t={}){this.type="Shape",this.parentId="",this.id=t.id?t.id:f(),this.name=t.name?t.name:f(),this.width=t.width?t.width:0,this.height=t.height?t.height:0,this.x=t.x?t.x:0,this.y=t.y?t.y:0,this.offscreenCanvas=wx.createOffscreenCanvas({type:"2d",width:this.width,height:this.height}),this.graphics=this.offscreenCanvas.getContext("2d")}getImage(){const t=this.offscreenCanvas.toDataURL("image/png"),e=this.offscreenCanvas.createImage();return e.src=t,e}}class V extends m{constructor(t){if(super(t),this.type="AnimatedSprite",this.json=t.json,this.anTextureList=[],this.loop=t.loop!==void 0?t.loop:!0,this.animationSpeed=t.animationSpeed?t.animationSpeed:15,this._playing=!1,this.currentFrame=t.currentFrame?t.currentFrame:0,this.json)for(let e in this.json.frames)this.anTextureList.push(this.json.frames[e].image)}play(t){t!==void 0&&(this.currentFrame=t),this._playing=!0}pause(){this._playing=!1}stop(t){this.currentFrame=t!==void 0?t:0,this._playing=!1}start(t={}){super.start(t)}_drawBackground(){super._drawBackground(),this._drawAnimation()}_drawAnimation(){if(this.anTextureList.length>0)if(this.currentFrame>=this.anTextureList.length?this.currentFrame=this.anTextureList.length-1:this.currentFrame<0&&(this.currentFrame=0),this._playing){this._lastUpdateTime||(this._lastUpdateTime=Date.now());const t=Date.now(),e=1e3/this.animationSpeed;t-this._lastUpdateTime>=e&&(this.texture=this.anTextureList[this.currentFrame],this.currentFrame++,this.currentFrame>=this.anTextureList.length&&(this.loop?this.currentFrame=0:(this.currentFrame=this.anTextureList.length-1,this._playing=!1)),this._lastUpdateTime=t)}else this.texture=this.anTextureList[this.currentFrame]}}exports.AnimatedSprite=V;exports.Layer=w;exports.Shape=Y;exports.Sprite=m;exports.default=X;