{"size": 2085, "ext": "js", "max_stars_repo_path": "web/mouseHit/js/classes/Animation.js", "max_stars_repo_name": "zhangshanfei/qeder", "max_stars_repo_stars_event_min_datetime": "2018-06-08T07:46:16.000Z", "max_stars_repo_stars_event_max_datetime": "2018-06-08T07:46:16.000Z", "max_issues_repo_path": "Public/Home/game/mouseHit/js/classes/Animation.js", "max_issues_repo_name": "yu520zhong/web", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "Public/Home/game/mouseHit/js/classes/Animation.js", "max_forks_repo_name": "yu520zhong/web", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 22.1808510638, "max_line_length": 98, "alphanum_fraction": 0.4613908873}
 /**
 * 逐帧动画组件
 */
(function() {

    var Animation = function(cfg) {

        /**
         * 动画图片
         */
        this.img = null;
        /**
         * 帧列表
         * @format {
         *     x: 0,
         *     y: 0,
         *     duration: 0,
         *     collRect: [[left, top, width, height]]
         * }
         */
        this.frames = [];
        /**
         * 循环播放
         */
        this.loop = true;
        /**
         * 播放倍速
         */
        this.speed = 1;
        /**
         * @read only
         * 播放状态
         */
        this.playing = false;
        /**
         * @read only
         * 正在播放的帧索引(第一帧从0开始)
         */
        this.currentFrameIndex = 0;
        /**
         * @read only
         * 正在播放的帧对象
         */
        this.currentFrame = null;
        /**
         * @private
         * 当前帧已播放次数
         */
        this.currentPlayeTimes = 0; //在Animation内部自定义这样，是为了让对象自控制自己的帧变换，间接影响这个数值快慢就是刷新canvas速率的快慢
		/**
		 * 多少次界面刷新更换一帧
		 */
		this.maxPlayTimes = 4 ;    
 
    }
 


    /**
     * 初始化
     */
     Animation.prototype.init=function(imageName,getFrameMethod,framesName){
	       this.img = my.ImageManager.get(imageName);
		   this.frames = getFrameMethod(framesName);   
		   this.currentFrameIndex = 0;
		   this.currentFrame= this.frames[this.currentFrameIndex];
		   this.currentFramePlayed = 0;
     }

    /**
     * normal状态更新
     */
	 Animation.prototype.update=function(){
	       if(this.currentPlayeTimes>=this.maxPlayTimes){
		      if(this.currentFrameIndex>= this.frames.length-2){ 
			       this.currentFrameIndex=0;
			  }else{			  
			       this.currentFrameIndex++;
			  }
		      this.currentFrame=this.frames[this.currentFrameIndex];
			  this.currentPlayeTimes=0;
		   }else{
		      this.currentPlayeTimes++;    
		   }
    }
	   
    Animation.prototype.draw=function(ct,x,y,w,h){
	       var f = this.currentFrame;
		   ct.drawImage(this.img,f.x,f.y,w,h,x,y,w,h);
    }

    my.Animation = Animation;
})();
