Raspsnir/public_html/browserquest/js/animation.js

1 line
848 B
JavaScript

define([],function(){var e=Class.extend({init:function(e,t,n,r,i){this.name=e,this.length=t,this.row=n,this.width=r,this.height=i,this.reset()},tick:function(){var e=this.currentFrame.index;e=e<this.length-1?e+1:0;if(this.count>0&&e===0){this.count-=1;if(this.count===0){this.currentFrame.index=0,this.endcount_callback();return}}this.currentFrame.x=this.width*e,this.currentFrame.y=this.height*this.row,this.currentFrame.index=e},setSpeed:function(e){this.speed=e},setCount:function(e,t){this.count=e,this.endcount_callback=t},isTimeToAnimate:function(e){return e-this.lastTime>this.speed},update:function(e){return this.lastTime===0&&this.name.substr(0,3)==="atk"&&(this.lastTime=e),this.isTimeToAnimate(e)?(this.lastTime=e,this.tick(),!0):!1},reset:function(){this.lastTime=0,this.currentFrame={index:0,x:0,y:this.row*this.height}}});return e});