/** * FatPixels: State-of-the-art pixel art animation and drawing. For the rest of us. * @author Matías Martínez http://matmartinez.net/ */(function(g,i,c){function j(q){for(var o=1;o=o){p.call();r=new Date().getTime()}q.value=k(n)}q.value=k(n);return q}function f(n){g.cancelAnimationFrame?g.cancelAnimationFrame(n.value):g.webkitCancelAnimationFrame?g.webkitCancelAnimationFrame(n.value):g.webkitCancelRequestAnimationFrame?g.webkitCancelRequestAnimationFrame(n.value):g.mozCancelRequestAnimationFrame?g.mozCancelRequestAnimationFrame(n.value):g.oCancelRequestAnimationFrame?g.oCancelRequestAnimationFrame(n.value):g.msCancelRequestAnimationFrame?g.msCancelRequestAnimationFrame(n.value):clearInterval(n)}var d={scale:1,autoplay:true,loop:true,speed:"15fps",};var a=function(n){if(!this.drawWithTarget){return new a(n)}this.options=j(n||{},{},d);this.bitmaps=null;this.bitmapSize={width:0,height:0};this.frames=null;this.frame=0;this.useSprite=this.options.sprite!=c;this.useArrayOfImages=this.options.images!=c};var e=function(n,o){this.buffer=i.createElement("canvas");this.buffer.width=n;this.buffer.height=o};e.prototype.drawInBuffer=function(n){this.buffer.getContext("2d").drawImage(n,0,0)};e.prototype.drawBufferInContext=function(n){n.drawImage(this.buffer,0,0)};a.prototype.renderFrames=function(M,L){var B=this.bitmaps;var D=this.bitmapSize;if(!B||L){var C=this;return C.getBitmaps(function(w,r){C.bitmaps=w;C.bitmapSize=r;C.renderFrames(M,false)})}var u=[];var K=this.options.scale,t=D.width*K,F=D.height*K;var n=i.createElement("canvas");n.width=t;n.height=F;var A=n.getContext("2d");for(var E=0;E1)}o.needsDisplay()})};a.prototype.drawingHandler=function(o,n){console.warn("FatPixels: Empty implementation for -drawingHandler.")};a.prototype.needsDisplay=function(){var s=this;var r=s.isAnimating,p=s.frames,o=s.frame;var n=s.options.onAnimation;var q=s.options.speed;if(typeof q=="string"||q instanceof String){if(l(q,"fps")){q=1000/parseFloat(q)}else{if(l(q,"ms")){q=parseFloat(q)}else{if(l(q,"s")){q=parseFloat(q)*1000}}}}if(!s.drawingInterval){s.drawingInterval=m(function(){o++;if(o==p.length){o=0;if(s.options.loop==false){setTimeout(function(){s.setAnimating(false)},1)}}s.drawingHandler(p[o],o);if(n){n(o)}},q)}if(!r){f(s.drawingInterval);delete s.drawingInterval}s.drawingHandler(p[o],o)};a.prototype.setAnimating=function(n){if(n!=this.isAnimating){this.isAnimating=n;this.needsDisplay()}};a.prototype.setFrame=function(n){if(n!=this.frame&&n