phaser-ce
Version:
Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
4 lines • 80.5 kB
JavaScript
/* Phaser v2.17.0 PIXI Build - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
(function(){function e(e,t,r,s){var o=e.createTexture();return e.bindTexture(e.TEXTURE_2D,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s===i.scaleModes.LINEAR?e.LINEAR:e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s===i.scaleModes.LINEAR?e.LINEAR:e.NEAREST),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,null),o}function t(t,r,i,o,a){var n=t.createFramebuffer(),h=t.createRenderbuffer(),l=null,u=0;return t.activeTexture(t.TEXTURE0+a),t.bindFramebuffer(t.FRAMEBUFFER,n),t.bindRenderbuffer(t.RENDERBUFFER,h),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_STENCIL_ATTACHMENT,t.RENDERBUFFER,this.renderBuffer),l=e(t,r,i,o),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,l,0),(u=t.checkFramebufferStatus(t.FRAMEBUFFER))!==t.FRAMEBUFFER_COMPLETE&&console.error("Incomplete GL framebuffer. ",s[u]),n.width=r,n.height=i,n.targetTexture=l,n.renderBuffer=h,n}var r=this,i=i||{};i.DisplayObject=function(){this.position=new i.Point(0,0),this.scale=new i.Point(1,1),this.pivot=new i.Point(0,0),this.rotation=0,this.alpha=1,this.visible=!0,this.hitArea=null,this.renderable=!1,this.parent=null,this.worldAlpha=1,this.worldTransform=new Phaser.Matrix,this.worldPosition=new i.Point(0,0),this.worldScale=new i.Point(1,1),this.worldRotation=0,this.filterArea=null,this._sr=0,this._cr=1,this._bounds=new i.Rectangle(0,0,0,0),this._currentBounds=null,this._mask=null,this._cacheAsBitmap=!1,this._cacheIsDirty=!1},i.DisplayObject.prototype={constructor:i.DisplayObject,destroy:function(){if(this.children){for(var e=this.children.length;e--;)this.children[e].destroy();this.children=[]}this.hitArea=null,this.parent=null,this.worldTransform=null,this.filterArea=null,this.renderable=!1,this._bounds=null,this._currentBounds=null,this._mask=null,this._destroyCachedSprite(),this._destroyTintedTexture()},updateTransform:function(e){if(!e&&!this.parent&&!this.game)return this;var t=this.parent;e?t=e:this.parent||(t=this.game.world);var r,i,s,o,a,n,h=t.worldTransform,l=this.worldTransform;this.rotation%Phaser.Math.PI2?(this.rotation!==this.rotationCache&&(this.rotationCache=this.rotation,this._sr=Math.sin(this.rotation),this._cr=Math.cos(this.rotation)),r=this._cr*this.scale.x,i=this._sr*this.scale.x,s=-this._sr*this.scale.y,o=this._cr*this.scale.y,a=this.position.x,n=this.position.y,(this.pivot.x||this.pivot.y)&&(a-=this.pivot.x*r+this.pivot.y*s,n-=this.pivot.x*i+this.pivot.y*o),l.a=r*h.a+i*h.c,l.b=r*h.b+i*h.d,l.c=s*h.a+o*h.c,l.d=s*h.b+o*h.d,l.tx=a*h.a+n*h.c+h.tx,l.ty=a*h.b+n*h.d+h.ty):(r=this.scale.x,i=0,s=0,o=this.scale.y,a=this.position.x-this.pivot.x*r,n=this.position.y-this.pivot.y*o,l.a=r*h.a,l.b=r*h.b,l.c=o*h.c,l.d=o*h.d,l.tx=a*h.a+n*h.c+h.tx,l.ty=a*h.b+n*h.d+h.ty),r=l.a,i=l.b,s=l.c;var u=r*(o=l.d)-i*s;if(r||i){var d=Math.sqrt(r*r+i*i);this.worldRotation=i>0?Math.acos(r/d):-Math.acos(r/d),this.worldScale.x=d,this.worldScale.y=u/d}else if(s||o){var c=Math.sqrt(s*s+o*o);this.worldRotation=Phaser.Math.HALF_PI-(o>0?Math.acos(-s/c):-Math.acos(s/c)),this.worldScale.x=u/c,this.worldScale.y=c}else this.worldScale.x=0,this.worldScale.y=0;return this.worldAlpha=this.alpha*t.worldAlpha,this.worldPosition.x=l.tx,this.worldPosition.y=l.ty,this._currentBounds=null,this.transformCallback&&this.transformCallback.call(this.transformCallbackContext,l,h),this},preUpdate:function(){},generateTexture:function(e,t,r){var s=this.getLocalBounds(),o=new Phaser.RenderTexture(this.game,0|s.width,0|s.height,r,t,e);return i.DisplayObject._tempMatrix.tx=-s.x,i.DisplayObject._tempMatrix.ty=-s.y,o.render(this,i.DisplayObject._tempMatrix),o},updateCache:function(){return this._generateCachedSprite(),this},toGlobal:function(e){return this.updateTransform(),this.worldTransform.apply(e)},toLocal:function(e,t){return t&&(e=t.toGlobal(e)),this.updateTransform(),this.worldTransform.applyInverse(e)},_renderCachedSprite:function(e){this._cachedSprite.worldAlpha=this.worldAlpha,e.gl?i.Sprite.prototype._renderWebGL.call(this._cachedSprite,e):i.Sprite.prototype._renderCanvas.call(this._cachedSprite,e)},_generateCachedSprite:function(){this._cacheAsBitmap=!1;var e=this.getLocalBounds();if(e.width=Math.max(1,Math.ceil(e.width)),e.height=Math.max(1,Math.ceil(e.height)),this.updateTransform(),this._cachedSprite)this._cachedSprite.texture.resize(e.width,e.height);else{var t=0;this.texture&&this.texture.baseTexture&&i._enableMultiTextureToggle&&(t=this.texture.baseTexture.textureIndex);var r=new Phaser.RenderTexture(this.game,e.width,e.height,void 0,void 0,void 0,void 0,t);this._cachedSprite=new i.Sprite(r),this._cachedSprite.worldTransform=this.worldTransform}var s=this._filters;this._filters=null,this._cachedSprite.filters=s,i.DisplayObject._tempMatrix.tx=-e.x,i.DisplayObject._tempMatrix.ty=-e.y,this._cachedSprite.texture.render(this,i.DisplayObject._tempMatrix,!0),this._cachedSprite.anchor.x=-e.x/e.width,this._cachedSprite.anchor.y=-e.y/e.height,this._filters=s,this._cacheAsBitmap=!0},_destroyCachedSprite:function(){this._cachedSprite&&(this._cachedSprite.texture.destroy(!0),this._cachedSprite=null)},_destroyTintedTexture:function(){this.tintedTexture&&(Phaser.CanvasPool.removeByCanvas(this.tintedTexture),this.tintedTexture=null)}},i.DisplayObject.prototype.displayObjectUpdateTransform=i.DisplayObject.prototype.updateTransform,Object.defineProperties(i.DisplayObject.prototype,{x:{get:function(){return this.position.x},set:function(e){this.position.x=e}},y:{get:function(){return this.position.y},set:function(e){this.position.y=e}},worldVisible:{get:function(){if(this.visible){var e=this.parent;if(!e)return this.visible;do{if(!e.visible)return!1;e=e.parent}while(e);return!0}return!1}},mask:{get:function(){return this._mask},set:function(e){this._mask&&(this._mask.isMask=!1),this._mask=e,e&&(this._mask.isMask=!0)}},filters:{get:function(){return this._filters},set:function(e){if(Array.isArray(e)){for(var t=[],r=0;r<e.length;r++)for(var s=e[r].passes,o=0;o<s.length;o++)t.push(s[o]);this._filterBlock={target:this,filterPasses:t}}this._filters=e,this.blendMode&&this.blendMode===i.blendModes.MULTIPLY&&(this.blendMode=i.blendModes.NORMAL)}},cacheAsBitmap:{get:function(){return this._cacheAsBitmap},set:function(e){this._cacheAsBitmap!==e&&(e?this._generateCachedSprite():this._destroyCachedSprite(),this._cacheAsBitmap=e)}}}),i.DisplayObjectContainer=function(){i.DisplayObject.call(this),this.children=[],this.ignoreChildInput=!1},i.DisplayObjectContainer.prototype=Object.create(i.DisplayObject.prototype),i.DisplayObjectContainer.prototype.constructor=i.DisplayObjectContainer,i.DisplayObjectContainer.prototype.addChild=function(e){return this.addChildAt(e,this.children.length)},i.DisplayObjectContainer.prototype.addChildAt=function(e,t){if(t>=0&&t<=this.children.length)return e.parent&&e.parent.removeChild(e),e.parent=this,this.children.splice(t,0,e),e;throw new Error(e+"addChildAt: The index "+t+" supplied is out of bounds "+this.children.length)},i.DisplayObjectContainer.prototype.swapChildren=function(e,t){if(e!==t){var r=this.getChildIndex(e),i=this.getChildIndex(t);if(r<0||i<0)throw new Error("swapChildren: Both the supplied DisplayObjects must be a child of the caller.");this.children[r]=t,this.children[i]=e}},i.DisplayObjectContainer.prototype.getChildIndex=function(e){var t=this.children.indexOf(e);if(-1===t)throw new Error("The supplied DisplayObject must be a child of the caller");return t},i.DisplayObjectContainer.prototype.setChildIndex=function(e,t){if(t<0||t>=this.children.length)throw new Error("The supplied index is out of bounds");var r=this.getChildIndex(e);this.children.splice(r,1),this.children.splice(t,0,e)},i.DisplayObjectContainer.prototype.getChildAt=function(e){if(e<0||e>=this.children.length)throw new Error("getChildAt: Supplied index "+e+" does not exist in the child list, or the supplied DisplayObject must be a child of the caller");return this.children[e]},i.DisplayObjectContainer.prototype.removeChild=function(e){var t=this.children.indexOf(e);if(-1!==t)return this.removeChildAt(t)},i.DisplayObjectContainer.prototype.removeChildAt=function(e){var t=this.getChildAt(e);return t&&(t.parent=void 0,this.children.splice(e,1)),t},i.DisplayObjectContainer.prototype.bringChildToTop=function(e){if(e.parent===this)return this.setChildIndex(e,this.children.length-1)},i.DisplayObjectContainer.prototype.sendChildToBack=function(e){if(e.parent===this)return this.setChildIndex(e,0)},i.DisplayObjectContainer.prototype.removeChildren=function(e,t){void 0===e&&(e=0),void 0===t&&(t=this.children.length);var r=t-e;if(r>0&&r<=t){for(var i=this.children.splice(e,r),s=0;s<i.length;s++)i[s].parent=void 0;return i}if(0===r&&0===this.children.length)return[];throw new Error("removeChildren: Range Error, numeric values are outside the acceptable range")},i.DisplayObjectContainer.prototype.updateTransform=function(){if(this.visible&&(this.displayObjectUpdateTransform(),!this._cacheAsBitmap))for(var e=0;e<this.children.length;e++)this.children[e].updateTransform()},i.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform=i.DisplayObjectContainer.prototype.updateTransform,i.DisplayObjectContainer.prototype.getBounds=function(e){var t=e&&e instanceof i.DisplayObject,r=!0;t?r=e instanceof i.DisplayObjectContainer&&e.contains(this):e=this;var s;if(t){var o=e.worldTransform;for(e.worldTransform=Phaser.identityMatrix,s=0;s<e.children.length;s++)e.children[s].updateTransform()}var a,n,h,l=1/0,u=1/0,d=-1/0,c=-1/0,f=!1;for(s=0;s<this.children.length;s++)this.children[s].visible&&(f=!0,l=l<(a=this.children[s].getBounds()).x?l:a.x,u=u<a.y?u:a.y,n=a.width+a.x,h=a.height+a.y,d=d>n?d:n,c=c>h?c:h);var x=this._bounds;if(!f){var p=(x=new i.Rectangle).x,g=x.width+x.x,T=x.y,v=x.height+x.y,m=this.worldTransform,E=m.a,_=m.b,S=m.c,y=m.d,b=m.tx,R=m.ty,A=E*g+S*v+b,M=y*v+_*g+R,C=E*p+S*v+b,L=y*v+_*p+R,B=E*p+S*T+b,P=y*T+_*p+R,w=E*g+S*T+b,U=y*T+_*g+R;d=A,c=M,u=M,l=w<(l=B<(l=C<(l=A)?C:l)?B:l)?w:l,u=U<(u=P<(u=L<u?L:u)?P:u)?U:u,d=w>(d=B>(d=C>d?C:d)?B:d)?w:d,c=U>(c=P>(c=L>c?L:c)?P:c)?U:c}if(x.x=l,x.y=u,x.width=d-l,x.height=c-u,t)for(e.worldTransform=o,s=0;s<e.children.length;s++)e.children[s].updateTransform();if(!r){var F=e.getBounds();x.x-=F.x,x.y-=F.y}return x},i.DisplayObjectContainer.prototype.getLocalBounds=function(){return this.getBounds(this)},i.DisplayObjectContainer.prototype.contains=function(e){return!!e&&(e===this||this.contains(e.parent))},i.DisplayObjectContainer.prototype._renderWebGL=function(e){if(this.visible&&!(this.alpha<=0))if(this._cacheAsBitmap)this._renderCachedSprite(e);else{var t;if(this._mask||this._filters){for(this._filters&&(e.spriteBatch.flush(),e.filterManager.pushFilter(this._filterBlock)),this._mask&&(e.spriteBatch.stop(),e.maskManager.pushMask(this.mask,e),e.spriteBatch.start()),t=0;t<this.children.length;t++)this.children[t]._renderWebGL(e);e.spriteBatch.stop(),this._mask&&e.maskManager.popMask(this._mask,e),this._filters&&e.filterManager.popFilter(),e.spriteBatch.start()}else for(t=0;t<this.children.length;t++)this.children[t]._renderWebGL(e)}},i.DisplayObjectContainer.prototype._renderCanvas=function(e){if(!1!==this.visible&&0!==this.alpha)if(this._cacheAsBitmap)this._renderCachedSprite(e);else{this._mask&&e.maskManager.pushMask(this._mask,e);for(var t=0;t<this.children.length;t++)this.children[t]._renderCanvas(e);this._mask&&e.maskManager.popMask(e)}},Object.defineProperty(i.DisplayObjectContainer.prototype,"width",{get:function(){return this.getLocalBounds().width*this.scale.x},set:function(e){var t=this.getLocalBounds().width;this.scale.x=0!==t?e/t:1,this._width=e}}),Object.defineProperty(i.DisplayObjectContainer.prototype,"height",{get:function(){return this.getLocalBounds().height*this.scale.y},set:function(e){var t=this.getLocalBounds().height;this.scale.y=0!==t?e/t:1,this._height=e}}),i.Sprite=function(e){i.DisplayObjectContainer.call(this),this.anchor=new i.Point(i.Sprite.defaultAnchor.x,i.Sprite.defaultAnchor.y),this.texture=e||i.Texture.emptyTexture,this._width=0,this._height=0,this.tint=16777215,this.cachedTint=-1,this.tintedTexture=null,this.blendMode=i.blendModes.NORMAL,this.shader=null,this.exists=!0,this.texture.baseTexture.hasLoaded&&this.onTextureUpdate(),this.renderable=!0},i.Sprite.defaultAnchor={x:0,y:0},i.Sprite.prototype=Object.create(i.DisplayObjectContainer.prototype),i.Sprite.prototype.constructor=i.Sprite,Object.defineProperty(i.Sprite.prototype,"width",{get:function(){return this.scale.x*this.texture.frame.width},set:function(e){this.scale.x=e/this.texture.frame.width,this._width=e}}),Object.defineProperty(i.Sprite.prototype,"height",{get:function(){return this.scale.y*this.texture.frame.height},set:function(e){this.scale.y=e/this.texture.frame.height,this._height=e}}),i.Sprite.prototype.setTexture=function(e,t){t&&this.texture.baseTexture.destroy(),this.texture.baseTexture.skipRender=!1,this.texture=e,this.texture.valid=!0,this.cachedTint=-1},i.Sprite.prototype.onTextureUpdate=function(){this._width&&(this.scale.x=this._width/this.texture.frame.width),this._height&&(this.scale.y=this._height/this.texture.frame.height)},i.Sprite.prototype.getBounds=function(e){var t=this.texture.frame.width,r=this.texture.frame.height,i=t*(1-this.anchor.x),s=t*-this.anchor.x,o=r*(1-this.anchor.y),a=r*-this.anchor.y,n=e||this.worldTransform,h=n.a,l=n.b,u=n.c,d=n.d,c=n.tx,f=n.ty,x=-1/0,p=-1/0,g=1/0,T=1/0;if(0===l&&0===u){if(h<0){h*=-1;v=i;i=-s,s=-v}if(d<0){d*=-1;var v=o;o=-a,a=-v}g=h*s+c,x=h*i+c,T=d*a+f,p=d*o+f}else{var m=h*s+u*a+c,E=d*a+l*s+f,_=h*i+u*a+c,S=d*a+l*i+f,y=h*i+u*o+c,b=d*o+l*i+f,R=h*s+u*o+c,A=d*o+l*s+f;g=R<(g=y<(g=_<(g=m<g?m:g)?_:g)?y:g)?R:g,T=A<(T=b<(T=S<(T=E<T?E:T)?S:T)?b:T)?A:T,x=R>(x=y>(x=_>(x=m>x?m:x)?_:x)?y:x)?R:x,p=A>(p=b>(p=S>(p=E>p?E:p)?S:p)?b:p)?A:p}var M=this._bounds;return M.x=g,M.width=x-g,M.y=T,M.height=p-T,this._currentBounds=M,M},i.Sprite.prototype.getLocalBounds=function(){var e=this.worldTransform;this.worldTransform=Phaser.identityMatrix;for(var t=0;t<this.children.length;t++)this.children[t].updateTransform();var r=this.getBounds();for(this.worldTransform=e,t=0;t<this.children.length;t++)this.children[t].updateTransform();return r},i.Sprite.prototype._renderWebGL=function(e,t){if(this.visible&&!(this.alpha<=0)&&this.renderable){var r=this.worldTransform;if(t&&(r=t),this._mask||this._filters){var i=e.spriteBatch;this._filters&&(i.flush(),e.filterManager.pushFilter(this._filterBlock)),this._mask&&(i.stop(),e.maskManager.pushMask(this.mask,e),i.start()),i.render(this);for(s=0;s<this.children.length;s++)this.children[s]._renderWebGL(e);i.stop(),this._mask&&e.maskManager.popMask(this._mask,e),this._filters&&e.filterManager.popFilter(),i.start()}else{e.spriteBatch.render(this);for(var s=0;s<this.children.length;s++)this.children[s]._renderWebGL(e,r)}}},i.Sprite.prototype._renderCanvas=function(e,t){if(!(!this.visible||0===this.alpha||!this.renderable||this.texture.crop.width<1||this.texture.crop.height<1)){var r=this.worldTransform;if(t&&(r=t),this.blendMode!==e.currentBlendMode&&(e.currentBlendMode=this.blendMode,e.context.globalCompositeOperation=i.blendModesCanvas[e.currentBlendMode]),this._mask&&e.maskManager.pushMask(this._mask,e),this.texture.valid){var s=this.texture.baseTexture.resolution/e.resolution;e.context.globalAlpha=this.worldAlpha,e.smoothProperty&&e.scaleMode!==this.texture.baseTexture.scaleMode&&(e.scaleMode=this.texture.baseTexture.scaleMode,e.context[e.smoothProperty]=e.scaleMode===i.scaleModes.LINEAR);var o=this.texture.trim?this.texture.trim.x-this.anchor.x*this.texture.trim.width:this.anchor.x*-this.texture.frame.width,a=this.texture.trim?this.texture.trim.y-this.anchor.y*this.texture.trim.height:this.anchor.y*-this.texture.frame.height,n=r.tx*e.resolution+e.shakeX,h=r.ty*e.resolution+e.shakeY,l=this.texture.crop.width,u=this.texture.crop.height;if(this.texture.rotated){var d=r.a,c=r.b,f=r.c,x=r.d,p=l;n=r.c*u+n,h=r.d*u+h,r.a=6.123233995736766e-17*d-f,r.b=6.123233995736766e-17*c-x,r.c=d+6.123233995736766e-17*f,r.d=c+6.123233995736766e-17*x,l=u,u=p}if(e.roundPixels?(e.context.setTransform(r.a,r.b,r.c,r.d,0|n,0|h),o|=0,a|=0):e.context.setTransform(r.a,r.b,r.c,r.d,n,h),o/=s,a/=s,l|=0,u|=0,l&&u){if(16777215!==this.tint)(this.texture.requiresReTint||this.cachedTint!==this.tint)&&(this.tintedTexture=i.CanvasTinter.getTintedTexture(this,this.tint),this.cachedTint=this.tint,this.texture.requiresReTint=!1),e.context.drawImage(this.tintedTexture,0,0,l,u,o,a,l/s,u/s);else{var g=this.texture.crop.x,T=this.texture.crop.y;e.context.drawImage(this.texture.baseTexture.source,g,T,l,u,o,a,l/s,u/s)}for(v=0;v<this.children.length;v++)this.children[v]._renderCanvas(e);this._mask&&e.maskManager.popMask(e)}}else{for(var v=0;v<this.children.length;v++)this.children[v]._renderCanvas(e);this._mask&&e.maskManager.popMask(e)}}},i.initDefaultShaders=function(){},i.CompileVertexShader=function(e,t){return i._CompileShader(e,t,e.VERTEX_SHADER)},i.CompileFragmentShader=function(e,t){return i._CompileShader(e,t,e.FRAGMENT_SHADER)},i._CompileShader=function(e,t,r){var i=t;Array.isArray(t)&&(i=t.join("\n"));var s=e.createShader(r);return e.shaderSource(s,i),e.compileShader(s),e.getShaderParameter(s,e.COMPILE_STATUS)?s:(window.console.log(e.getShaderInfoLog(s)),null)},i.compileProgram=function(e,t,r){var s=i.CompileFragmentShader(e,r),o=i.CompileVertexShader(e,t),a=e.createProgram();return e.attachShader(a,o),e.attachShader(a,s),e.linkProgram(a),e.getProgramParameter(a,e.LINK_STATUS)||(window.console.log(e.getProgramInfoLog(a)),window.console.log("Could not initialise shaders")),a},i.PixiShader=function(e){this._UID=Phaser._UID++,this.gl=e,this.program=null,this.fragmentSrc=null,this.textureCount=0,this.firstRun=!0,this.dirty=!0,this.attributes=[],this.init()},i.PixiShader.prototype.constructor=i.PixiShader,i.PixiShader.prototype.initMultitexShader=function(){var e=this.gl;this.MAX_TEXTURES=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(var t="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;return;}\n",r=1;r<this.MAX_TEXTURES;++r)t+="\tif (vTextureIndex == "+r+".0) {gl_FragColor = texture2D(uSamplerArray["+r+"], vTextureCoord) * vColor;return;}\n";this.fragmentSrc=["// PixiShader Fragment Shader.","precision lowp float;","bool isnan( float val ) { return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true; }","varying vec2 vTextureCoord;","varying vec4 vColor;","varying float vTextureIndex;","uniform sampler2D uSamplerArray["+this.MAX_TEXTURES+"];","const vec4 BLUE = vec4(1.0, 0.0, 1.0, 1.0);","const vec4 RED = vec4(1.0, 0.0, 0.0, 1.0);","void main(void) {",t," if(vTextureIndex >= "+this.MAX_TEXTURES+".0) { gl_FragColor = BLUE;return;}"," if(isnan(vTextureIndex)) { gl_FragColor = RED;return;}","}"];var s=i.compileProgram(e,this.vertexSrc||i.PixiShader.defaultVertexSrc,this.fragmentSrc);e.useProgram(s),this.uSamplerArray=e.getUniformLocation(s,"uSamplerArray[0]"),this.projectionVector=e.getUniformLocation(s,"projectionVector"),this.offsetVector=e.getUniformLocation(s,"offsetVector"),this.dimensions=e.getUniformLocation(s,"dimensions"),this.aVertexPosition=e.getAttribLocation(s,"aVertexPosition"),this.aTextureCoord=e.getAttribLocation(s,"aTextureCoord"),this.colorAttribute=e.getAttribLocation(s,"aColor"),this.aTextureIndex=e.getAttribLocation(s,"aTextureIndex");var o=[],a=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,a),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var n=0;n<this.MAX_TEXTURES;++n)e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_2D,a),o.push(n);e.activeTexture(e.TEXTURE0),e.uniform1iv(this.uSamplerArray,o),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.colorAttribute,this.aTextureIndex];for(var h in this.uniforms)this.uniforms[h].uniformLocation=e.getUniformLocation(s,h);this.initUniforms(),this.program=s},i.PixiShader.prototype.initDefaultShader=function(){null===this.fragmentSrc&&(this.fragmentSrc=["precision lowp float;","varying vec2 vTextureCoord;","varying vec4 vColor;","varying float vTextureIndex;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor ;","}"]);var e=this.gl,t=i.compileProgram(e,this.vertexSrc||i.PixiShader.defaultVertexSrc,this.fragmentSrc);e.useProgram(t),this.uSampler=e.getUniformLocation(t,"uSampler"),this.projectionVector=e.getUniformLocation(t,"projectionVector"),this.offsetVector=e.getUniformLocation(t,"offsetVector"),this.dimensions=e.getUniformLocation(t,"dimensions"),this.aVertexPosition=e.getAttribLocation(t,"aVertexPosition"),this.aTextureCoord=e.getAttribLocation(t,"aTextureCoord"),this.colorAttribute=e.getAttribLocation(t,"aColor"),this.aTextureIndex=e.getAttribLocation(t,"aTextureIndex"),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.colorAttribute,this.aTextureIndex];for(var r in this.uniforms)this.uniforms[r].uniformLocation=e.getUniformLocation(t,r);this.initUniforms(),this.program=t},i.PixiShader.prototype.init=function(e){i._enableMultiTextureToggle&&!e?this.initMultitexShader():this.initDefaultShader()},i.PixiShader.prototype.initUniforms=function(){this.textureCount=1;var e,t=this.gl;for(var r in this.uniforms){var i=(e=this.uniforms[r]).type;"sampler2D"===i?(e._init=!1,null!==e.value&&this.initSampler2D(e)):"mat2"===i||"mat3"===i||"mat4"===i?(e.glMatrix=!0,e.glValueLength=1,"mat2"===i?e.glFunc=t.uniformMatrix2fv:"mat3"===i?e.glFunc=t.uniformMatrix3fv:"mat4"===i&&(e.glFunc=t.uniformMatrix4fv)):(e.glFunc=t["uniform"+i],e.glValueLength="2f"===i||"2i"===i?2:"3f"===i||"3i"===i?3:"4f"===i||"4i"===i?4:1)}},i.PixiShader.prototype.initSampler2D=function(e){if(e.value&&e.value.baseTexture&&e.value.baseTexture.hasLoaded){var t=this.gl;if(t.activeTexture(t.TEXTURE0+this.textureCount),t.bindTexture(t.TEXTURE_2D,e.value.baseTexture._glTextures[t.id]),e.textureData){var r=e.textureData,i=r.magFilter?r.magFilter:t.LINEAR,s=r.minFilter?r.minFilter:t.LINEAR,o=r.wrapS?r.wrapS:t.CLAMP_TO_EDGE,a=r.wrapT?r.wrapT:t.CLAMP_TO_EDGE,n=r.luminance?t.LUMINANCE:t.RGBA;if(r.repeat&&(o=t.REPEAT,a=t.REPEAT),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,!!r.flipY),r.width){var h=r.width?r.width:512,l=r.height?r.height:2,u=r.border?r.border:0;t.texImage2D(t.TEXTURE_2D,0,n,h,l,u,n,t.UNSIGNED_BYTE,null)}else t.texImage2D(t.TEXTURE_2D,0,n,t.RGBA,t.UNSIGNED_BYTE,e.value.baseTexture.source);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,a)}t.uniform1i(e.uniformLocation,this.textureCount),e._init=!0,this.textureCount++}},i.PixiShader.prototype.syncUniforms=function(){this.textureCount=1;var e,t=this.gl;for(var r in this.uniforms)1===(e=this.uniforms[r]).glValueLength?!0===e.glMatrix?e.glFunc.call(t,e.uniformLocation,e.transpose,e.value):e.glFunc.call(t,e.uniformLocation,e.value):2===e.glValueLength?e.glFunc.call(t,e.uniformLocation,e.value.x,e.value.y):3===e.glValueLength?e.glFunc.call(t,e.uniformLocation,e.value.x,e.value.y,e.value.z):4===e.glValueLength?e.glFunc.call(t,e.uniformLocation,e.value.x,e.value.y,e.value.z,e.value.w):"sampler2D"===e.type&&(e._init?(t.activeTexture(t["TEXTURE"+this.textureCount]),e.value.baseTexture._dirty[t.id]?i.instances[t.id].updateTexture(e.value.baseTexture):t.bindTexture(t.TEXTURE_2D,e.value.baseTexture._glTextures[t.id]),t.uniform1i(e.uniformLocation,this.textureCount),this.textureCount++):this.initSampler2D(e))},i.PixiShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},i.PixiShader.defaultVertexSrc=["// PixiShader Vertex Shader","// With multi-texture rendering","attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute vec4 aColor;","attribute float aTextureIndex;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying vec4 vColor;","varying float vTextureIndex;","const vec2 center = vec2(-1.0, 1.0);","void main(void) {"," if (aTextureIndex > 0.0) gl_Position = vec4(0.0);"," gl_Position = vec4( ((aVertexPosition + offsetVector) / projectionVector) + center , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vColor = vec4(aColor.rgb * aColor.a, aColor.a);"," vTextureIndex = aTextureIndex;","}"],i.PixiFastShader=function(e){if(this._UID=Phaser._UID++,this.gl=e,this.program=null,i._enableMultiTextureToggle){var e=this.gl;this.MAX_TEXTURES=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(var t="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;return;}\n",r=1;r<this.MAX_TEXTURES;++r)t+="\tif (vTextureIndex == "+r+".0) { gl_FragColor = texture2D(uSamplerArray["+r+"], vTextureCoord) * vColor;return;}\n";this.fragmentSrc=["// PixiFastShader Fragment Shader.","precision lowp float;","bool isnan( float val ) { return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true; }","varying vec2 vTextureCoord;","varying float vColor;","varying float vTextureIndex;","uniform sampler2D uSamplerArray["+this.MAX_TEXTURES+"];","const vec4 BLUE = vec4(1.0, 0.0, 1.0, 1.0);","const vec4 RED = vec4(1.0, 0.0, 0.0, 1.0);","void main(void) {",t," if(vTextureIndex >= "+this.MAX_TEXTURES+".0) { gl_FragColor = BLUE;return;}"," if(isnan(vTextureIndex)) {gl_FragColor = RED;return;}","}"]}else this.fragmentSrc=["// PixiFastShader Fragment Shader.","precision lowp float;","varying vec2 vTextureCoord;","varying float vColor;","varying float vTextureIndex;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;","}"];this.vertexSrc=["// PixiFastShader Vertex Shader.","attribute vec2 aVertexPosition;","attribute vec2 aPositionCoord;","attribute vec2 aScale;","attribute float aRotation;","attribute vec2 aTextureCoord;","attribute float aColor;","attribute float aTextureIndex;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","uniform mat3 uMatrix;","varying vec2 vTextureCoord;","varying float vColor;","varying float vTextureIndex;","const vec2 center = vec2(-1.0, 1.0);","void main(void) {"," vec2 v;"," vec2 sv = aVertexPosition * aScale;"," v.x = (sv.x) * cos(aRotation) - (sv.y) * sin(aRotation);"," v.y = (sv.x) * sin(aRotation) + (sv.y) * cos(aRotation);"," v = ( uMatrix * vec3(v + aPositionCoord , 1.0) ).xy ;"," gl_Position = vec4( ( v / projectionVector) + center , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vTextureIndex = aTextureIndex;"," vColor = aColor;","}"],this.textureCount=0,this.init()},i.PixiFastShader.prototype.constructor=i.PixiFastShader,i.PixiFastShader.prototype.init=function(){var e=this.gl,t=i.compileProgram(e,this.vertexSrc,this.fragmentSrc);if(e.useProgram(t),this.uSampler=i._enableMultiTextureToggle?e.getUniformLocation(t,"uSamplerArray[0]"):e.getUniformLocation(t,"uSampler"),i._enableMultiTextureToggle){var r=[],s=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var o=0;o<this.MAX_TEXTURES;++o)e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,s),r.push(o);e.activeTexture(e.TEXTURE0),e.uniform1iv(this.uSampler,r)}this.projectionVector=e.getUniformLocation(t,"projectionVector"),this.offsetVector=e.getUniformLocation(t,"offsetVector"),this.dimensions=e.getUniformLocation(t,"dimensions"),this.uMatrix=e.getUniformLocation(t,"uMatrix"),this.aVertexPosition=e.getAttribLocation(t,"aVertexPosition"),this.aPositionCoord=e.getAttribLocation(t,"aPositionCoord"),this.aScale=e.getAttribLocation(t,"aScale"),this.aRotation=e.getAttribLocation(t,"aRotation"),this.aTextureCoord=e.getAttribLocation(t,"aTextureCoord"),this.colorAttribute=e.getAttribLocation(t,"aColor"),this.aTextureIndex=e.getAttribLocation(t,"aTextureIndex"),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aPositionCoord,this.aScale,this.aRotation,this.aTextureCoord,this.colorAttribute,this.aTextureIndex],this.program=t},i.PixiFastShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},i.StripShader=function(e){if(this._UID=Phaser._UID++,this.gl=e,this.program=null,i._enableMultiTextureToggle){var e=this.gl;this.MAX_TEXTURES=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(var t="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord);return;}\n",r=1;r<this.MAX_TEXTURES;++r)t+="\tif (vTextureIndex == "+r+".0) { gl_FragColor = texture2D(uSamplerArray["+r+"], vTextureCoord) ;return;}\n";this.fragmentSrc=["//StripShader Fragment Shader.","precision mediump float;","bool isnan( float val ) { return ( val < 0.0 || 0.0 < val || val == 0.0 ) ? false : true; }","varying vec2 vTextureCoord;","varying float vTextureIndex;","uniform float alpha;","uniform sampler2D uSamplerArray["+this.MAX_TEXTURES+"];","const vec4 BLUE = vec4(1.0, 0.0, 1.0, 1.0);","const vec4 RED = vec4(1.0, 0.0, 0.0, 1.0);","void main(void) {",t," if(vTextureIndex >= "+this.MAX_TEXTURES+".0) { gl_FragColor = BLUE;return;}"," if(isnan(vTextureIndex)) {gl_FragColor = RED;return;}","}"]}else this.fragmentSrc=["//StripShader Fragment Shader.","precision mediump float;","varying vec2 vTextureCoord;","varying float vTextureIndex;","uniform float alpha;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vTextureCoord);","}"];this.vertexSrc=["//StripShader Vertex Shader.","attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","attribute float aTextureIndex;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","varying vec2 vTextureCoord;","varying float vTextureIndex;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, v.y / -projectionVector.y + 1.0 , 0.0, 1.0);"," vTextureCoord = aTextureCoord;"," vTextureIndex = aTextureIndex;","}"],this.init()},i.StripShader.prototype.constructor=i.StripShader,i.StripShader.prototype.init=function(){var e=this.gl,t=i.compileProgram(e,this.vertexSrc,this.fragmentSrc);if(e.useProgram(t),this.uSampler=i._enableMultiTextureToggle?e.getUniformLocation(t,"uSamplerArray[0]"):e.getUniformLocation(t,"uSampler"),i._enableMultiTextureToggle){var r=[],s=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,s),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var o=0;o<this.MAX_TEXTURES;++o)e.activeTexture(e.TEXTURE0+o),e.bindTexture(e.TEXTURE_2D,s),r.push(o);e.activeTexture(e.TEXTURE0),e.uniform1iv(this.uSampler,r)}this.projectionVector=e.getUniformLocation(t,"projectionVector"),this.offsetVector=e.getUniformLocation(t,"offsetVector"),this.colorAttribute=e.getAttribLocation(t,"aColor"),this.aTextureIndex=e.getAttribLocation(t,"aTextureIndex"),this.aVertexPosition=e.getAttribLocation(t,"aVertexPosition"),this.aTextureCoord=e.getAttribLocation(t,"aTextureCoord"),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.aTextureIndex],this.translationMatrix=e.getUniformLocation(t,"translationMatrix"),this.alpha=e.getUniformLocation(t,"alpha"),this.program=t},i.StripShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},i.PrimitiveShader=function(e){this._UID=Phaser._UID++,this.gl=e,this.program=null,this.fragmentSrc=["precision mediump float;","varying vec4 vColor;","void main(void) {"," gl_FragColor = vColor;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","attribute vec4 aColor;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","uniform float alpha;","uniform float flipY;","uniform vec3 tint;","varying vec4 vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, (v.y / projectionVector.y * -flipY) + flipY , 0.0, 1.0);"," vColor = aColor * vec4(tint * alpha, alpha);","}"],this.init()},i.PrimitiveShader.prototype.constructor=i.PrimitiveShader,i.PrimitiveShader.prototype.init=function(){var e=this.gl,t=i.compileProgram(e,this.vertexSrc,this.fragmentSrc);e.useProgram(t),this.projectionVector=e.getUniformLocation(t,"projectionVector"),this.offsetVector=e.getUniformLocation(t,"offsetVector"),this.tintColor=e.getUniformLocation(t,"tint"),this.flipY=e.getUniformLocation(t,"flipY"),this.aVertexPosition=e.getAttribLocation(t,"aVertexPosition"),this.colorAttribute=e.getAttribLocation(t,"aColor"),this.attributes=[this.aVertexPosition,this.colorAttribute],this.translationMatrix=e.getUniformLocation(t,"translationMatrix"),this.alpha=e.getUniformLocation(t,"alpha"),this.program=t},i.PrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},i.ComplexPrimitiveShader=function(e){this._UID=Phaser._UID++,this.gl=e,this.program=null,this.fragmentSrc=["precision mediump float;","varying vec4 vColor;","void main(void) {"," gl_FragColor = vColor;","}"],this.vertexSrc=["attribute vec2 aVertexPosition;","uniform mat3 translationMatrix;","uniform vec2 projectionVector;","uniform vec2 offsetVector;","uniform vec3 tint;","uniform float alpha;","uniform vec3 color;","uniform float flipY;","varying vec4 vColor;","void main(void) {"," vec3 v = translationMatrix * vec3(aVertexPosition , 1.0);"," v -= offsetVector.xyx;"," gl_Position = vec4( v.x / projectionVector.x -1.0, (v.y / projectionVector.y * -flipY) + flipY , 0.0, 1.0);"," vColor = vec4(color * alpha * tint, alpha);","}"],this.init()},i.ComplexPrimitiveShader.prototype.constructor=i.ComplexPrimitiveShader,i.ComplexPrimitiveShader.prototype.init=function(){var e=this.gl,t=i.compileProgram(e,this.vertexSrc,this.fragmentSrc);e.useProgram(t),this.projectionVector=e.getUniformLocation(t,"projectionVector"),this.offsetVector=e.getUniformLocation(t,"offsetVector"),this.tintColor=e.getUniformLocation(t,"tint"),this.color=e.getUniformLocation(t,"color"),this.flipY=e.getUniformLocation(t,"flipY"),this.aVertexPosition=e.getAttribLocation(t,"aVertexPosition"),this.attributes=[this.aVertexPosition,this.colorAttribute],this.translationMatrix=e.getUniformLocation(t,"translationMatrix"),this.alpha=e.getUniformLocation(t,"alpha"),this.program=t},i.ComplexPrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},i.glContexts=[],i.instances=[],i._enableMultiTextureToggle=!1,i.WebGLRenderer=function(e,t){this.game=e,i.defaultRenderer||(i.defaultRenderer=this),this.extensions={},this.type=Phaser.WEBGL,this.resolution=e.resolution,this.transparent=e.transparent,this.autoResize=!1,this.preserveDrawingBuffer=e.preserveDrawingBuffer,this.clearBeforeRender=e.clearBeforeRender,this.powerPreference=e.powerPreference,this.width=e.width,this.height=e.height,this.view=e.canvas,this._contextOptions={alpha:this.transparent,antialias:e.antialias,failIfMajorPerformanceCaveat:t.failIfMajorPerformanceCaveat,premultipliedAlpha:this.transparent&&"notMultiplied"!==this.transparent,stencil:!0,preserveDrawingBuffer:this.preserveDrawingBuffer,powerPreference:e.powerPreference},this.projection=new i.Point,this.offset=new i.Point,this.shaderManager=new i.WebGLShaderManager,this.spriteBatch=new i.WebGLSpriteBatch(e),this.maskManager=new i.WebGLMaskManager,this.filterManager=new i.WebGLFilterManager,this.stencilManager=new i.WebGLStencilManager,this.blendModeManager=new i.WebGLBlendModeManager,this.renderSession={},this.currentBatchedTextures=[],this.renderSession.game=this.game,this.renderSession.gl=this.gl,this.renderSession.drawCount=0,this.renderSession.shaderManager=this.shaderManager,this.renderSession.maskManager=this.maskManager,this.renderSession.filterManager=this.filterManager,this.renderSession.blendModeManager=this.blendModeManager,this.renderSession.spriteBatch=this.spriteBatch,this.renderSession.stencilManager=this.stencilManager,this.renderSession.renderer=this,this.renderSession.resolution=this.resolution,this.renderSession.roundPixels=t.roundPixels||!1,this.renderSession.maxTextureAvailableSpace=null,this.initContext(),this.mapBlendModes()},i.WebGLRenderer.prototype.constructor=i.WebGLRenderer,i.WebGLRenderer.prototype.initContext=function(){var e=this.view.getContext("webgl",this._contextOptions)||this.view.getContext("experimental-webgl",this._contextOptions);if(this.gl=e,!e)throw new Error("This browser does not support webGL. Try using the canvas renderer");this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxTextureSize=this.gl.getParameter(e.MAX_TEXTURE_SIZE),this.glContextId=e.id=i.WebGLRenderer.glContextId++,i.glContexts[this.glContextId]=e,i.instances[this.glContextId]=this,e.disable(e.DEPTH_TEST),e.disable(e.CULL_FACE),e.enable(e.BLEND),this.shaderManager.setContext(e),this.spriteBatch.setContext(e),this.maskManager.setContext(e),this.filterManager.setContext(e),this.blendModeManager.setContext(e),this.stencilManager.setContext(e),this.renderSession.gl=this.gl,this.resize(this.width,this.height),this.extensions.compression={};var t=e.getExtension("WEBGL_compressed_texture_etc1")||e.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),r=e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),s=e.getExtension("WEBGL_compressed_texture_s3tc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");t&&(this.extensions.compression.ETC1=t),r&&(this.extensions.compression.PVRTC=r),s&&(this.extensions.compression.S3TC=s)},i.WebGLRenderer.prototype.setTexturePriority=function(e){if(i._enableMultiTextureToggle){for(var t=function(e){return--e,e|=e>>1,e|=e>>2,e|=e>>4,e|=e>>8,e|=e>>16,++e},r=this.gl,s=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),o=r.getParameter(r.MAX_TEXTURE_SIZE),a=this.game.cache._cache.image,n=null,h=0;h<this.currentBatchedTextures.length;h++)(n=this.currentBatchedTextures[h])in a?a[n].base.textureIndex=0:console.warn('setTexturePriority: There is no image "%s" in the image cache.',n);var l=o-t(Math.max(this.width,this.height));this.currentBatchedTextures.length=0;for(var u=0;u<e.length;++u)if((n=e[u])in a){var d=a[n].base;(l-=t(Math.max(d.width,d.height)))<=0?(d.textureIndex=0,console.warn('setTexturePriority: Image "%s" was given textureIndex=0 because there is no available texture space (%s).',n,l)):d.textureIndex=1+u%(s-1),this.currentBatchedTextures.push(n)}else console.warn('setTexturePriority: There is no image "%s" in the image cache.',n);return this.renderSession.maxTextureAvailableSpace=l,this.currentBatchedTextures}console.warn("setTexturePriority error: Multi Texture support hasn't been enabled in the Phaser Game Config.")},i.WebGLRenderer.prototype.render=function(e){if(!this.contextLost){var t=this.gl;t.viewport(0,0,this.width,this.height),t.bindFramebuffer(t.FRAMEBUFFER,null),this.game.clearBeforeRender&&(t.clearColor(e._bgColor.r,e._bgColor.g,e._bgColor.b,e._bgColor.a),t.clear(t.COLOR_BUFFER_BIT)),this.offset.x=this.game.camera._shake.x,this.offset.y=this.game.camera._shake.y,this.renderDisplayObject(e,this.projection)}},i.WebGLRenderer.prototype.postRender=function(){this.gl.flush()},i.WebGLRenderer.prototype.renderDisplayObject=function(e,t,r,s){this.renderSession.blendModeManager.setBlendMode(i.blendModes.NORMAL),this.renderSession.drawCount=0,this.renderSession.flipY=r?-1:1,this.renderSession.projection=t,this.renderSession.offset=this.offset,this.spriteBatch.begin(this.renderSession),this.filterManager.begin(this.renderSession,r),e._renderWebGL(this.renderSession,s),this.spriteBatch.end()},i.WebGLRenderer.prototype.resize=function(e,t){this.width=e*this.resolution,this.height=t*this.resolution,this.view.width=this.width,this.view.height=this.height,this.autoResize&&(this.view.style.width=this.width/this.resolution+"px",this.view.style.height=this.height/this.resolution+"px"),this.gl.viewport(0,0,this.width,this.height),this.projection.x=this.width/2/this.resolution,this.projection.y=-this.height/2/this.resolution},i.WebGLRenderer.prototype.updateCompressedTexture=function(e){if(!e.hasLoaded)return!1;var t=this.gl,r=e.source;return e._glTextures[t.id]||(e._glTextures[t.id]=t.createTexture()),t.activeTexture(t.TEXTURE0+e.textureIndex),t.bindTexture(t.TEXTURE_2D,e._glTextures[t.id]),t.compressedTexImage2D(t.TEXTURE_2D,0,r.glExtensionFormat,r.width,r.height,0,r.textureData),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR:t.NEAREST),e.mipmap&&Phaser.Math.isPowerOfTwo(e.width,e.height)?(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR_MIPMAP_LINEAR:t.NEAREST_MIPMAP_NEAREST),t.generateMipmap(t.TEXTURE_2D)):t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR:t.NEAREST),e._powerOf2?(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.REPEAT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.REPEAT)):(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),e._dirty[t.id]=!1,!0},i.WebGLRenderer.prototype.updateTexture=function(e){if(!e.hasLoaded||!e.source)return!1;if(e.source.compressionAlgorithm)return this.updateCompressedTexture(e);var t=this.gl;return e._glTextures[t.id]||(e._glTextures[t.id]=t.createTexture()),t.activeTexture(t.TEXTURE0+e.textureIndex),t.bindTexture(t.TEXTURE_2D,e._glTextures[t.id]),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,e.premultipliedAlpha),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e.source),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR:t.NEAREST),e.mipmap&&Phaser.Math.isPowerOfTwo(e.width,e.height)?(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR_MIPMAP_LINEAR:t.NEAREST_MIPMAP_NEAREST),t.generateMipmap(t.TEXTURE_2D)):t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,e.scaleMode===i.scaleModes.LINEAR?t.LINEAR:t.NEAREST),e._powerOf2?(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.REPEAT),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.REPEAT)):(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),e._dirty[t.id]=!1,!0},i.WebGLRenderer.prototype.destroy=function(){i.glContexts[this.glContextId]=null,this.projection=null,this.offset=null,this.shaderManager.destroy(),this.spriteBatch.destroy(),this.maskManager.destroy(),this.filterManager.destroy(),this.shaderManager=null,this.spriteBatch=null,this.maskManager=null,this.filterManager=null,this.gl=null,this.renderSession=null,Phaser.CanvasPool.remove(this),i.instances[this.glContextId]=null,i.WebGLRenderer.glContextId--},i.WebGLRenderer.prototype.mapBlendModes=function(){var e=this.gl;if(!i.blendModesWebGL){var t=[],r=i.blendModes;t[r.NORMAL]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.ADD]=[e.SRC_ALPHA,e.DST_ALPHA],t[r.MULTIPLY]=[e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA],t[r.SCREEN]=[e.SRC_ALPHA,e.ONE],t[r.OVERLAY]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.DARKEN]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.LIGHTEN]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.COLOR_DODGE]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.COLOR_BURN]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.HARD_LIGHT]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.SOFT_LIGHT]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.DIFFERENCE]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.EXCLUSION]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.HUE]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.SATURATION]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.COLOR]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],t[r.LUMINOSITY]=[e.ONE,e.ONE_MINUS_SRC_ALPHA],i.blendModesWebGL=t}},i.WebGLRenderer.prototype.getMaxTextureUnit=function(){var e=this.gl;return e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)},i.enableMultiTexture=function(){i._enableMultiTextureToggle=!0},i.WebGLRenderer.glContextId=0,i.WebGLRenderer.textureArray=[],i.WebGLBlendModeManager=function(){this.currentBlendMode=99999},i.WebGLBlendModeManager.prototype.constructor=i.WebGLBlendModeManager,i.WebGLBlendModeManager.prototype.setContext=function(e){this.gl=e},i.WebGLBlendModeManager.prototype.setBlendMode=function(e){if(this.currentBlendMode===e)return!1;this.currentBlendMode=e;var t=i.blendModesWebGL[this.currentBlendMode];return t&&this.gl.blendFunc(t[0],t[1]),!0},i.WebGLBlendModeManager.prototype.destroy=function(){this.gl=null},i.WebGLMaskManager=function(){},i.WebGLMaskManager.prototype.constructor=i.WebGLMaskManager,i.WebGLMaskManager.prototype.setContext=function(e){this.gl=e},i.WebGLMaskManager.prototype.pushMask=function(e,t){var r=t.gl;e.dirty&&i.WebGLGraphics.updateGraphics(e,r),void 0!==e._webGL[r.id]&&void 0!==e._webGL[r.id].data&&0!==e._webGL[r.id].data.length&&t.stencilManager.pushStencil(e,e._webGL[r.id].data[0],t)},i.WebGLMaskManager.prototype.popMask=function(e,t){var r=this.gl;void 0!==e._webGL[r.id]&&void 0!==e._webGL[r.id].data&&0!==e._webGL[r.id].data.length&&t.stencilManager.popStencil(e,e._webGL[r.id].data[0],t)},i.WebGLMaskManager.prototype.destroy=function(){this.gl=null},i.WebGLStencilManager=function(){this.stencilStack=[],this.reverse=!0,this.count=0},i.WebGLStencilManager.prototype.setContext=function(e){this.gl=e},i.WebGLStencilManager.prototype.pushStencil=function(e,t,r){var i=this.gl;this.bindGraphics(e,t,r),0===this.stencilStack.length&&(i.enable(i.STENCIL_TEST),i.clear(i.STENCIL_BUFFER_BIT),this.reverse=!0,this.count=0),this.stencilStack.push(t);var s=this.count;i.colorMask(!1,!1,!1,!1),i.stencilFunc(i.ALWAYS,0,255),i.stencilOp(i.KEEP,i.KEEP,i.INVERT),1===t.mode?(i.drawElements(i.TRIANGLE_FAN,t.indices.length-4,i.UNSIGNED_SHORT,0),this.reverse?(i.stencilFunc(i.EQUAL,255-s,255),i.stencilOp(i.KEEP,i.KEEP,i.DECR)):(i.stencilFunc(i.EQUAL,s,255),i.stencilOp(i.KEEP,i.KEEP,i.INCR)),i.drawElements(i.TRIANGLE_FAN,4,i.UNSIGNED_SHORT,2*(t.indices.length-4)),this.reverse?i.stencilFunc(i.EQUAL,255-(s+1),255):i.stencilFunc(i.EQUAL,s+1,255),this.reverse=!this.reverse):(this.reverse?(i.stencilFunc(i.EQUAL,s,255),i.stencilOp(i.KEEP,i.KEEP,i.INCR)):(i.stencilFunc(i.EQUAL,255-s,255),i.stencilOp(i.KEEP,i.KEEP,i.DECR)),i.drawElements(i.TRIANGLE_STRIP,t.indices.length,i.UNSIGNED_SHORT,0),this.reverse?i.stencilFunc(i.EQUAL,s+1,255):i.stencilFunc(i.EQUAL,255-(s+1),255)),i.colorMask(!0,!0,!0,!0),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),this.count++},i.WebGLStencilManager.prototype.bindGraphics=function(e,t,r){this._currentGraphics=e;var i,s=this.gl,o=r.projection,a=r.offset;1===t.mode?(i=r.shaderManager.complexPrimitiveShader,r.shaderManager.setShader(i),s.uniform1f(i.flipY,r.flipY),s.uniformMatrix3fv(i.translationMatrix,!1,e.worldTransform.toArray(!0)),s.uniform2f(i.projectionVector,o.x,-o.y),s.uniform2f(i.offsetVector,-a.x,-a.y),s.uniform3fv(i.tintColor,Phaser.Color.hexToRGBArray(e.tint)),s.uniform3fv(i.color,t.color),s.uniform1f(i.alpha,e.worldAlpha*t.alpha),s.bindBuffer(s.ARRAY_BUFFER,t.buffer),s.vertexAttribPointer(i.aVertexPosition,2,s.FLOAT,!1,8,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.indexBuffer)):(i=r.shaderManager.primitiveShader,r.shaderManager.setShader(i),s.uniformMatrix3fv(i.translationMatrix,!1,e.worldTransform.toArray(!0)),s.uniform1f(i.flipY,r.flipY),s.uniform2f(i.projectionVector,o.x,-o.y),s.uniform2f(i.offsetVector,-a.x,-a.y),s.uniform3fv(i.tintColor,Phaser.Color.hexToRGBArray(e.tint)),s.uniform1f(i.alpha,e.worldAlpha),s.bindBuffer(s.ARRAY_BUFFER,t.buffer),s.vertexAttribPointer(i.aVertexPosition,2,s.FLOAT,!1,24,0),s.vertexAttribPointer(i.colorAttribute,4,s.FLOAT,!1,24,8),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,t.indexBuffer))},i.WebGLStencilManager.prototype.popStencil=function(e,t,r){var i=this.gl;if(this.stencilStack.pop(),this.count--,0===this.stencilStack.length)i.disable(i.STENCIL_TEST);else{var s=this.count;this.bindGraphics(e,t,r),i.colorMask(!1,!1,!1,!1),1===t.mode?(this.reverse=!this.reverse,this.reverse?(i.stencilFunc(i.EQUAL,255-(s+1),255),i.stencilOp(i.KEEP,i.KEEP,i.INCR)):(i.stencilFunc(i.EQUAL,s+1,255),i.stencilOp(i.KEEP,i.KEEP,i.DECR)),i.drawElements(i.TRIANGLE_FAN,4,i.UNSIGNED_SHORT,2*(t.indices.length-4)),i.stencilFunc(i.ALWAYS,0,255),i.stencilOp(i.KEEP,i.KEEP,i.INVERT),i.drawElements(i.TRIANGLE_FAN,t.indices.length-4,i.UNSIGNED_SHORT,0),this.reverse?i.stencilFunc(i.EQUAL,s,255):i.stencilFunc(i.EQUAL,255-s,255)):(this.reverse?(i.stencilFunc(i.EQUAL,s+1,255),i.stencilOp(i.KEEP,i.KEEP,i.DECR)):(i.stencilFunc(i.EQUAL,255-(s+1),255),i.stencilOp(i.KEEP,i.KEEP,i.INCR)),i.drawElements(i.TRIANGLE_STRIP,t.indices.length,i.UNSIGNED_SHORT,0),this.reverse?i.stencilFunc(i.EQUAL,s,255):i.stencilFunc(i.EQUAL,255-s,255)),i.colorMask(!0,!0,!0,!0),i.stencilOp(i.KEEP,i.KEEP,i.KEEP)}},i.WebGLStencilManager.prototype.destroy=function(){this.stencilStack=null,this.gl=null},i.WebGLShaderManager=function(){this.maxAttibs=10,this.attribState=[],this.tempAttribState=[];for(var e=0;e<this.maxAttibs;e++)this.attribState[e]=!1;this.stack=[]},i.WebGLShaderManager.prototype.constructor=i.WebGLShaderManager,i.WebGLShaderManager.prototype.setContext=function(e){this.gl=e,this.primitiveShader=new i.PrimitiveShader(e),this.complexPrimitiveShader=new i.ComplexPrimitiveShader(e),this.defaultShader=new i.PixiShader(e),this.fastShader=new i.PixiFastShader(e),this.stripShader=new i.StripShader(e),this.creatureShader=i.CreatureShader?new i.CreatureShader(e):null,this.setShader(this.defaultShader)},i.WebGLShaderManager.prototype.setAttribs=function(e){var t;for(t=0;t<this.tempAttribState.length;t++)this.tempAttribState[t]=!1;for(t=0;t<e.length;t++){var r=e[t];this.tempAttribState[r]=!0}var i=this.gl;for(t=0;t<this.attribState.length;t++)this.attribState[t]!==this.tempAttribState[t]&&(this.attribState[t]=this.tempAttribState[t],this.tempAttribState[t]?i.enableVertexAttribArray(t):i.disableVertexAttribArray(t))},i.WebGLShaderManager.prototype.setShader=function(e){return this._currentId!==e._UID&&(this._currentId=e._UID,this.currentShader=e,this.gl.useProgram(e.program),this.setAttribs(e.attributes),!0)},i.WebGLShaderManager.prototype.destroy=function(){this.attribState=null,this.tempAttribState=null,this.primitiveShader.destroy(),this.complexPrimitiveShader.destroy(),this.defaultShader.destroy(),this.fastShader.destroy(),this.stripShader.destroy(),this.creatureShader&&this.creatureShader.destroy(),this.gl=null},i.WebGLSpriteBatch=function(e){this.game=e,this.vertSize=5,this.size=2e3,this.vertexSize=24;var t=this.vertexSize*this.size*4,r=6*this.size;this.vertices=new ArrayBuffer(t),this.positions=new Float32Array(this.vertices),this.colors=new Uint32Array(this.vertices),this.indices=new Uint16Array(r),this.lastIndexCount=0;for(var i=0,s=0;i<r;i+=6,s+=4)this.indices[i+0]=s+0,this.indices[i+1]=s+1,this.indices[i+2]=s+2,this.indices[i+3]=s+0,this.indices[i+4]=s+2,this.indices[i+5]=s+3;this.drawing=!1,this.currentBatchSize=0,this.currentBaseTexture=null,this.dirty=!0,this.textures=[],this.blendModes=[],this.shaders=[],this.sprites=[],this.defaultShader=null},i.WebGLSpriteBatch.prototype.setContext=function(e){if(this.MAX_TEXTURES=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.gl=e,i._enableMultiTextureToggle){for(var t="\tif (vTextureIndex == 0.0) {gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;return;}\n",r=1;r<this.MAX_TEXTURES;++r)t+="\tif (vTextureIndex == "+r+".0) {gl_FragColor = texture2D(uSamplerArray["+r+"], vTextureCoord) * vColor;return;}\n";this.defaultShader=new Phaser.Filter(this.game,void 0,["//WebGLSpriteBatch Fragment Shader.","precision lowp float;","varying vec2 vTextureCoord;","varying vec4 vColor;","varying float vTextureIndex;","uniform sampler2D uSamplerArray["+this.MAX_TEXTURES+"];","void main(void) {",t,"\tgl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;","}"])}else this.defaultShader=new Phaser.Filter(this.game,void 0,["//WebGLSpriteBatch Fragment Shader.","precision lowp float;","varying vec2 vTextureCoord;","varying vec4 vColor;","varying float vTextureIndex;","uniform sampler2D uSampler;","void main(void) {"," gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;","}"]);this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,this.indices,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.vertices,e.DYNAMIC_DRAW),this.currentBlendMode=99999;var s=new i.PixiShader(e);s.fragmentSrc=this.defaultShader.fragmentSrc,s.uniforms={},s.init(),this.defaultShader.shaders[e.id]=s},i.WebGLSpriteBatch.prototype.begin=function(e){this.renderSession=e,this.shader=this.renderSession.shaderManager.defaultShader,this.start()},i.WebGLSpriteBatch.prototype.end=function(){this.flush()},i.WebGLSpriteBatch.prototype.render=function(e,t){var r=e.texture,s=r.baseTexture,o=this.gl;i.WebGLRenderer.textureArray[s.textureIndex]!=s&&(this.flush(),o.activeTexture(o.TEXTURE0+s.textureIndex),o.bindTexture(o.TEXTURE_2D,s._glTextures[o.id]),i.WebGLRenderer.textureArray[s.textureIndex]=s);var a=e.worldTransform;t&&(a=t),this.currentBatchSize>=this.size&&(this.flush(),this.currentBaseTexture=r.baseTexture);var n=r._uvs;if(n){var h,l,u,d,c=e.anchor.x,f=e.anchor.y;if(r.trim){var x=r.trim;h=(l=x.x-c*x.width)+r.crop.width,u=(d=x.y-f*x.height)+r.crop.height}else h=r.frame.width*(1-c),l=r.frame.width*-c,u=r.frame.height*(1-f),d=r.frame.height*-f;var p=this.currentBatchSize*this.vertexSize,g=r.baseTexture.resolution,T=r.baseTexture.textureIndex,v=a.a/g,m=a.b/g,E=a.c/g,_=a.d/g,S=a.tx,y=a.ty,b=r.crop.height;if(r.rotated){var R=a.a,A=a.b,M=a.c,C=a.d,L=l,B=h;S=a.c*b+S,y=a.d*b+y,v=6.123233995736766e-17*R-M,m=6.123233995736766e-17*A-C,E=R+6.123233995736766e-17*M,_=A+6.123233995736766e-17*C,r._updateUvsInverted(),h=u,l=d,u=B,d=L}var P=this.colors,w=this.positions,U=e.tint,F=(U>>16)+(65280&U)+((255&U)<<16)+(255*e.worldAlpha<<24);this.renderSession.roundPixels?(w[p++]=v*l+E*d+S|0,w[p++]=_*d+m*l+y|0,w[p++]=n.x0,w[p++]=n.y0,P[p++]=F,w[p++]=T,w[p++]=v*h+E*d+S|0,w[p++]=_*d+m*h+y|0,w[p++]=n.x1,w[p++]=n.y1,P[p++]=F,w[p++]=T,w[p++]=v*h+E*u+S|0,w[p++]=_*u+m*h+y|0,w[p++]=n.x2,w[p++]=n.y2,P[p++]=F,w[p++]=T,w[p++]=v*l+E*u+S|0,w[p++]=_*u+m*l+y|0,w[p++]=n.x3,w[p++]=n.y3,P[p++]=F,w[p++]=T):(w[p++]=v*l+E*d+S,w[p++]=_*d+m*l+y,w[p++]=n.x0,w[p++]=n.y0,P[p++]=F,w[p++]=T,w[p++]=v*h+E*d+S,w[p++]=_*d+m*h+y,w[p++]=n.x1,w[p++]=n.y1,P[p++]=F,w[p++]=T,w[p++]=v*h+E*u+S,w[p++]=_*u+m*h+y,w[p++]=n.x2,w[p++]=n.y2,P[p++]=F,w[p++]=T,w[p++]=v*l+E*u+S,w[p++]=_*u+m*l+y,w[p++]=n.x3,w[p++]=n.y3,P[p++]=F,w[p++]=T),this.sprites[this.currentBatchSize++]=e}},i.WebGLSpriteBatch.prototype.renderTilingSprite=function(e){var t=e.tilingTexture,r=t.baseTexture,s=this.gl,o=e.texture.baseTexture.textureIndex;i.WebGLRenderer.textureArray[o]!=r&&(this.flush(),s.activeTexture(s.TEXTURE0+o),s.bindTexture(s.TEXTURE_2D,r._glTextures[s.id]),i.WebGLRenderer.textureArray[o]=r),this.currentBatchSize>=this.size&&(this.flush(),this.currentBaseTexture=t.baseTexture),e._uvs||(e._uvs=new i.TextureUvs);var a=e._uvs,n=t.baseTexture.width,h=t.baseTexture.height;e.tilePosition.x%=n*e.tileScaleOffset.x,e.tilePosition.y%=h*e.tileScaleOffset.y;var l=e.tilePosition.x/(n*e.tileScaleOffset.x),u=e.tilePosition.y/(h*e.tileScaleOffset.y),d=e.width/n/(e.tileScale.x*e.tileScaleOffset.x),c=e.height/h/(e.tileScale.y*e.tileScaleOffset.y);a.x0=0-l,a.y0=0-u,a.x1=1*d-l,a.y1=0-u,a.x2=1*d-l,a.y2=1*c-u,a.x3=0-l,a.y3=1*c-u;var f=e.tint,x=(f>>16)+(65280&f)+((255&f)<<16)+(255*e.worldAlpha<<24),p=this.positions,g=this.colors,T=e.width,v=e.height,m=e.anchor.x,E=e.anchor.y,_=T*(1-m),S=T*-m,y=v*(1-E),b=v*-E,R=this.currentBatchSize*this.vertexSize,A=t.baseTexture.resolution,M=e.worldTransform,C=M.a/A,L=M.b/A,B=M.c/A,P=M.d/A,w=M.tx,U=M.ty;p[R++]=C*S+B*b+w,p[R++]=P*b+L*S+U,p[R++]=a.x0,p[R++]=a.y0,g[R++]=x,p[R++]=o,p[R++]=C*_+B*b+w,p[R++]=P*b+L*_+U,p[R++]=a.x1,p[R++]=a.y1,g[R++]=x,p[R++]=o,p[R++]=C*_+B*y+w,p[R++]=P*y+L*_+U,p[R++]=a.x2,p[R++]=a.y2,g[R++]=x,p[R++]=o,p[R++]=C*S+B*y+w,p[R++]=P*y+L*S+U,p[R++]=a.x3,p[R++]=a.y3,g[R++]=x,p[R++]=o,this.sprites[this.currentBatchSize++]=e},i.WebGLSpriteBatch.prototype.flush=function(){if(0!==this.currentBatchSize){var e,t=this.gl;if(this.dirty){this.dirty=!1,e=this.defaultShader.shaders[t.id],t.activeTexture(t.TEXTURE0),t.bindBuffer(t.ARRAY_BUFFER,this.vertexBuffer),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this.indexBuffer);var r=this.vertexSize;t.vertexAttribPointer(e.aVertexPosition,2,t.FLOAT,!1,r,0),t.vertexAttribPointer(e.aTextureCoord,2,t.FLOAT,!1,r,8),t.vertexAttribPointer(e.colorAttribute,4,t.UNSIGNED_BYTE,!0,r,16),t.vertexAttribPointer(e.aTextureIndex,1,t.FLOAT,!1,r,20)}if(this.currentBatchSize>.5*this.size)t.bufferSubData(t.ARRAY_BUFFER,0,this.vertices);else{t.bindBuffer(t.ARRAY_BUFFER,this.vertexBuffer);var s=this.positions.subarray(0,this.currentBatchSize*this.vertexSize);t.bufferSubData(t.ARRAY_BUFFER,0,s)}for(var o,a,n,h,l=0,u=0,d=null,c=this.renderSession.blendModeManager.currentBlendMode,f=null,x=!1,p=!1,g=0,T=this.currentBatchSize;g<T;g++){o=(h=this.sprites[g]).tilingTexture?h.tilingTexture.baseTexture:h.texture.baseTexture,x=c!==(a=h.blendMode),p=f!==(n=h.shader||this.defaultShader);var v=o.skipRender;if(v&&h.children.length>0&&(v=!1),(x||p)&&(this.renderBatch(d,l,u),u=g,l=0,d=o,x&&(c=a,this.renderSession.blendModeManager.setBlendMode(c)),p)){(e=(f=n).shaders[t.id])||((e=new i.PixiShader(t)).fragmentSrc=f.fragmentSrc,e.uniforms=f.uniforms,e.init(),f.shaders[t.id]=e),this.renderSession.shaderManager.setShader(e),e.dirty&&e.syncUniforms();var m=this.renderSession.projection;t.uniform2f(e.projectionVector,m.x,m.y);var E=this.renderSession.offset;t.uniform2f(e.offsetVector,E.x,E.y)}l++}this.renderBatch(d,l,u),this.currentBatchSize=0}},i.WebGLSpriteBatch.prototype.renderBatch=function(e,t,r){if(0!==t){var i=this.gl;if(e._dirty[i.id]){if(!this.renderSession.renderer.updateTexture(e))return}else i.bindTexture(i.TEXTURE_2D,e._glTextures[i.id]);i.drawElements(i.TRIANGLES,6*t,i.UNSIGNED_SHORT,6*r*2),this.renderSession.drawCount++}},i.WebGLSpriteBatch.prototype.stop=function(){this.flush(),this.dirty=!0},i.WebGLSpriteBatch.prototype.start=function(){this.dirty=!0},i.WebGLSpriteBatch.prototype.destroy=function(){this.vertices=null,this.indices=null,this.gl.deleteBuffer(this.vertexBuffer),this.gl.deleteBuffer(this.indexBuffer),this.currentBaseTexture=null,this.gl=null},i.WebGLFastSpriteBatch=function(e){this.vertSize=11,this.maxSize=6e3,this.size=this.maxSize;var t=4*this.size*this.vertSize,r=6*this.maxSize;this.vertices=new Float32Array(t),this.indices=new Uint16Array(r),this.vertexBuffer=null,this.indexBuffer=null,this.lastIndexCount=0;for(var i=0,s=0;i<r;i+=6,s+=4)this.indices[i+0]=s+0,this.indices[i+1]=s+1,this.indices[i+2]=s+2,this.indices[i+3]=s+0,this.indices[i+4]=s+2,this.indices[i+5]=s+3;this.drawing=!1,this.currentBatchSize=0,this.currentBaseTexture=null,this.currentBlendMode=0,this.renderSession=null,this.shader=null,this.matrix=null,this.setContext(e)},i.WebGLFastSpriteBatch.prototype.constructor=i.WebGLFastSpriteBatch,i.WebGLFastSpriteBatch.prototype.setContext=function(e){this.gl=e,this.vertexBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,this.indices,e.STATIC_DRAW),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.vertices,e.DYNAMIC_DRAW)},i.WebGLFastSpriteBatch.prototype.begin=function(e,t){this.renderSession=t,this.shader=this.renderSession.shaderManager.fastShader,this.matrix=e.worldTransform.toArray(!0),this.start()},i.WebGLFastSpriteBatch.prototype.end=function(){this.flush()},i.WebGLFastSpriteBatch.prototype.render=function(e){var t=e.children,r=t[0];if(r.texture._uvs){this.currentBaseTexture=r.texture.baseTexture,r.blendMode!==this.renderSession.blendModeManager.currentBlendMode&&(this.flush(),this.renderSession.blendModeManager.setBlendMode(r.blendMode));var s=this.currentBaseTexture.textureIndex,o=this.gl;o.activeTexture(o.TEXTURE0+s),o.bindTexture(o.TEXTURE_2D,this.currentBaseTexture._glTextures[o.id]),i.WebGLRenderer.textureArray[s]=this.currentBaseTexture;for(var a=0,n=t.length;a<n;a++)this.renderSprite(t[a]);this.flush()}},i.WebGLFastSpriteBatch.prototype.renderSprite=function(e){var t=e.texture.baseTexture,r=this.gl,s=e.texture.baseTexture.textureIndex;if((i.WebGLRenderer.textureArray[s]==t||!t._glTextures[r.id]||e.texture.baseTexture.skipRender||(this.flush(),r.activeTexture(r.TEXTURE0+s),r.bindTexture(r.TEXTURE_2D,t._glTextures[r.id]),i.WebGLRenderer.textureArray[s]=t,e.texture._uvs))&&e.visible){var o,a,n,h,l,u,d,c,f=this.vertices;if(o=e.texture._uvs,a=e.texture.frame.width,n=e.texture.frame.height,e.texture.trim){var x=e.texture.trim;h=(l=x.x-e.anchor.x*x.width)+e.texture.crop.width,u=(d=x.y-e.anchor.y*x.height)+e.texture.crop.height}else h=a*(1-e.anchor.x),l=a*-e.anchor.x,u=n*(1-e.anchor.y),d=n*-e.anchor.y;c=4*this.currentBatchSize*this.vertSize,f[c++]=l,f[c++]=d,f[c++]=e.position.x,f[c++]=e.position.y,f[c++]=e.scale.x,f[c++]=e.scale.y,f[c++]=e.rotation,f[c++]=o.x0,f[c++]=o.y1,f[c++]=e.alpha,f[c++]=s,f[c++]=h,f[c++]=d,f[c++]=e.position.x,f[c++]=e.position.y,f[c++]=e.scale.x,f[c++]=e.scale.y,f[c++]=e.rotation,f[c++]=o.x1,f[c++]=o.y1,f[c++]=e.alpha,f[c++]=s,f[c++]=h,f[c++]=u,f[c++]=e.position.x,f[c++]=e.position.y,f[c++]=e.scale.x,f[c++]=e.scale.y,f[c++]=e.rotation,f[c++]=o.x2,f[c++]=o.y2,f[c++]=e.alpha,f[c++]=s,f[c++]=l,f[c++]=u,f[c++]=e.position.x,f[c++]=e.position.y,f[c++]=e.scale.x,f[c++]=e.scale.y,f[c++]=e.rotation,f[c++]=o.x3,f[c++]=o.y3,f[c++]=e.alpha,f[c++]=s,++this.currentBatchSize>=this.size&&this.flush()}},i.WebGLFastSpriteBatch.prototype.flush=function(){if(0!==this.currentBatchSize){var e=this.gl;if(this.currentBaseTexture._glTextures[e.id]){if(this.currentBatchSize>.5*this.size)e.bufferSubData(e.ARRAY_BUFFER,0,this.vertices);else{var t=this.vertices.subarray(0,4*this.currentBatchSize*this.vertSize);e.bufferSubData(e.ARRAY_BUFFER,0,t)}e.drawElements(e.TRIANGLES,6*this.currentBatchSize,e.UNSIGNED_SHORT,0),this.currentBatchSize=0,this.renderSession.drawCount++}else this.renderSession.renderer.updateTexture(this.currentBaseTexture,e)}},i.WebGLFastSpriteBatch.prototype.stop=function(){this.flush()},i.WebGLFastSpriteBatch.prototype.start=function(){var e=this.gl;e.activeTexture(e.TEXTURE0),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer);var t=this.renderSession.projection;e.uniform2f(this.shader.projectionVector,t.x,t.y),e.uniformMatrix3fv(this.shader.uMatrix,!1,this.matrix);var r=4*this.vertSize;e.vertexAttribPointer(this.shader.aVertexPosition,2,e.FLOAT,!1,r,0),e.vertexAttribPointer(this.shader.aPositionCoord,2,e.FLOAT,!1,r,8),e.vertexAttribPointer(this.shader.aScale,2,e.FLOAT,!1,r,16),e.vertexAttribPointer(this.shader.aRotation,1,e.FLOAT,!1,r,24),e.vertexAttribPointer(this.shader.aTextureCoord,2,e.FLOAT,!1,r,28),e.vertexAttribPointer(this.shader.colorAttribute,1,e.FLOAT,!1,r,36),e.vertexAttribPointer(this.shader.aTextureIndex,1,e.FLOAT,!1,r,40)},i.WebGLFilterManager=function(){this.filterStack=[],this.offsetX=0,this.offsetY=0},i.WebGLFilterManager.prototype.constructor=i.WebGLFilterManager,i.WebGLFilterManager.prototype.setContext=function(e){this.gl=e,this.texturePool=[],this.initShaderBuffers()},i.WebGLFilterManager.prototype.begin=function(e,t){this.renderSession=e,this.defaultShader=e.shaderManager.defaultShader;var r=this.renderSession.projection;this.width=2*r.x,this.height=2*-r.y,this.buffer=t},i.WebGLFilterManager.prototype.pushFilter=function(e){var t=this.gl,r=this.renderSession.projection,s=this.renderSession.offset;e._filterArea=e.target.filterArea||e.target.getBounds(),e._previous_stencil_mgr=this.renderSession.stencilManager,this.renderSession.stencilManager=new i.WebGLStencilManager,this.renderSession.stencilManager.setContext(t),t.disable(t.STENCIL_TEST),this.filterStack.push(e);var o=e.filterPasses[0];this.offsetX+=e._filterArea.x,this.offsetY+=e._filterArea.y;var a=this.texturePool.pop();a?a.resize(this.width*this.renderSession.resolution,this.height*this.renderSession.resolution):a=new i.FilterTexture(this.gl,this.width*this.renderSession.resolution,this.height*this.renderSession.resolution),t.bindTexture(t.TEXTURE_2D,a.texture);var n=e._filterArea,h=o.padding;n.x-=h,n.y-=h,n.width+=2*h,n.height+=2*h,n.x<0&&(n.x=0),n.width>this.width&&(n.width=this.width),n.y<0&&(n.y=0),n.height>this.height&&(n.height=this.height),t.bindFramebuffer(t.FRAMEBUFFER,a.frameBuffer),t.viewport(0,0,n.width*this.renderSession.resolution,n.height*this.renderSession.resolution),r.x=n.width/2,r.y=-n.height/2,s.x=-n.x,s.y=-n.y,t.colorMask(!0,!0,!0,!0),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),e._glFilterTexture=a},i.WebGLFilterManager.prototype.popFilter=function(){var e=this.gl,t=this.filterStack.pop(),r=t._filterArea,s=t._glFilterTexture,o=this.renderSession.projection,a=this.renderSession.offset;if(t.filterPasses.length>1){e.viewport(0,0,r.width*this.renderSession.resolution,r.height*this.renderSession.resolution),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),this.vertexArray[0]=0,this.vertexArray[1]=r.height,this.vertexArray[2]=r.width,this.vertexArray[3]=r.height,this.vertexArray[4]=0,this.vertexArray[5]=0,this.vertexArray[6]=r.width,this.vertexArray[7]=0,e.bufferSubData(e.ARRAY_BUFFER,0,this.vertexArray),e.bindBuffer(e.ARRAY_BUFFER,this.uvBuffer),this.uvArray[2]=r.width/this.width,this.uvArray[5]=r.height/this.height,this.uvArray[6]=r.width/this.width,this.uvArray[7]=r.height/this.height,e.bufferSubData(e.ARRAY_BUFFER,0,this.uvArray);var n=s,h=this.texturePool.pop();h||(h=new i.FilterTexture(this.gl,this.width*this.renderSession.resolution,this.height*this.renderSession.resolution)),h.resize(this.width*this.renderSession.resolution,this.height*this.renderSession.resolution),e.bindFramebuffer(e.FRAMEBUFFER,h.frameBuffer),e.clear(e.COLOR_BUFFER_BIT),e.disable(e.BLEND);for(var l=0;l<t.filterPasses.length-1;l++){var u=t.filterPasses[l];e.bindFramebuffer(e.FRAMEBUFFER,h.frameBuffer),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,n.texture),this.applyFilterPass(u,r,r.width,r.height);var d=n;n=h,h=d}e.enable(e.BLEND),s=n,this.texturePool.push(h)}var c=t.filterPasses[t.filterPasses.length-1];this.offsetX-=r.x,this.offsetY-=r.y;var f=this.width,x=this.height,p=0,g=0,T=this.buffer;if(0===this.filterStack.length)e.colorMask(!0,!0,!0,!0);else{var v=this.filterStack[this.filterStack.length-1];f=(r=v._filterArea).width,x=r.height,p=r.x,g=r.y,T=v._glFilterTexture.frameBuffer}o.x=f/2,o.y=-x/2,a.x=p,a.y=g;var m=(r=t._filterArea).x-p,E=r.y-g;e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),this.vertexArray[0]=m,this.vertexArray[1]=E+r.height,this.vertexArray[2]=m+r.width,this.vertexArray[3]=E+r.height,this.vertexArray[4]=m,this.vertexArray[5]=E,this.vertexArray[6]=m+r.width,this.vertexArray[7]=E,e.bufferSubData(e.ARRAY_BUFFER,0,this.vertexArray),e.bindBuffer(e.ARRAY_BUFFER,this.uvBuffer),this.uvArray[2]=r.width/this.width,this.uvArray[5]=r.height/this.height,this.uvArray[6]=r.width/this.width,this.uvArray[7]=r.height/this.height,e.bufferSubData(e.ARRAY_BUFFER,0,this.uvArray),e.viewport(0,0,f*this.renderSession.resolution,x*this.renderSession.resolution),e.bindFramebuffer(e.FRAMEBUFFER,T),e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,s.texture),this.renderSession.stencilManager&&this.renderSession.stencilManager.destroy(),this.renderSession.stencilManager=t._previous_stencil_mgr,t._previous_stencil_mgr=null,this.renderSession.stencilManager.count>0?e.enable(e.STENCIL_TEST):e.disable(e.STENCIL_TEST),this.applyFilterPass(c,r,f,x),this.texturePool.push(s),t._glFilterTexture=null},i.WebGLFilterManager.prototype.applyFilterPass=function(e,t,r,s){var o=this.gl,a=e.shaders[o.id];a||((a=new i.PixiShader(o)).fragmentSrc=e.fragmentSrc,a.uniforms=e.uniforms,a.init(!0),e.shaders[o.id]=a),this.renderSession.shaderManager.setShader(a),o.uniform2f(a.projectionVector,r/2,-s/2),o.uniform2f(a.offsetVector,0,0),e.uniforms.dimensions&&(e.uniforms.dimensions.value[0]=this.width,e.uniforms.dimensions.value[1]=this.height,e.uniforms.dimensions.value[2]=this.vertexArray[0],e.uniforms.dimensions.value[3]=this.vertexArray[5]),a.syncUniforms(),o.bindBuffer(o.ARRAY_BUFFER,this.vertexBuffer),o.vertexAttribPointer(a.aVertexPosition,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.uvBuffer),o.vertexAttribPointer(a.aTextureCoord,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.colorBuffer),o.vertexAttribPointer(a.colorAttribute,2,o.FLOAT,!1,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this.indexBuffer),o.drawElements(o.TRIANGLES,6,o.UNSIGNED_SHORT,0),this.renderSession.drawCount++},i.WebGLFilterManager.prototype.initShaderBuffers=function(){var e=this.gl;this.vertexBuffer=e.createBuffer(),this.uvBuffer=e.createBuffer(),this.colorBuffer=e.createBuffer(),this.indexBuffer=e.createBuffer(),this.vertexArray=new Float32Array([0,0,1,0,0,1,1,1]),e.bindBuffer(e.ARRAY_BUFFER,this.vertexBuffer),e.bufferData(e.ARRAY_BUFFER,this.vertexArray,e.STATIC_DRAW),this.uvArray=new Float32Array([0,0,1,0,0,1,1,1]),e.bindBuffer(e.ARRAY_BUFFER,this.uvBuffer),e.bufferData(e.ARRAY_BUFFER,this.uvArray,e.STATIC_DRAW),this.colorArray=new Float32Array([1,16777215,1,16777215,1,16777215,1,16777215]),e.bindBuffer(e.ARRAY_BUFFER,this.colorBuffer),e.bufferData(e.ARRAY_BUFFER,this.colorArray,e.STATIC_DRAW),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,this.indexBuffer),e.bufferData(e.ELEMENT_ARRAY_BUFFER,new Uint16Array([0,1,2,1,3,2]),e.STATIC_DRAW)},i.WebGLFilterManager.prototype.destroy=function(){var e=this.gl;this.filterStack=null,this.offsetX=0,this.offsetY=0;for(var t=0;t<this.texturePool.length;t++)this.texturePool[t].destroy();this.texturePool=null,e.deleteBuffer(this.vertexBuffer),e.deleteBuffer(this.uvBuffer),e.deleteBuffer(this.colorBuffer),e.deleteBuffer(this.indexBuffer)};var s={36054:"Incomplete attachment",36055:"Missing attachment",36057:"Incomplete dimensions",36061:"Framebuffer unsupported"};return i.FilterTexture=function(e,r,s,o,a){a="number"==typeof a?a:0,this.gl=e,this.frameBuffer=t(e,r,s,o||i.scaleModes.DEFAULT,a),this.texture=this.frameBuffer.targetTexture,this.width=r,this.height=s,this.renderBuffer=this.frameBuffer.renderBuffer},i.FilterTexture.prototype.constructor=i.FilterTexture,i.FilterTexture.prototype.clear=function(){var e=this.gl;e.clearColor(0,0,0,0),e.clear(e.COLOR_BUFFER_BIT)},i.FilterTexture.prototype.resize=function(e,t){if(this.width!==e||this.height!==t){this.width=e,this.height=t;var r=this.gl;r.bindTexture(r.TEXTURE_2D,this.texture),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,e,t,0,r.RGBA,r.UNSIGNED_BYTE,null),r.bindRenderbuffer(r.RENDERBUFFER,this.renderBuffer),r.renderbufferStorage(r.RENDERBUFFER,r.DEPTH_STENCIL,e,t)}},i.FilterTexture.prototype.destroy=function(){var e=this.gl;e.deleteFramebuffer(this.frameBuffer),e.deleteTexture(this.texture),this.frameBuffer=null,this.texture=null},i.CanvasBuffer=function(e,t){this.width=e,this.height=t,this.canvas=Phaser.CanvasPool.create(this,this.width,this.height),this.context=this.canvas.getContext("2d"),this.canvas.width=e,this.canvas.height=t},i.CanvasBuffer.prototype.constructor=i.CanvasBuffer,i.CanvasBuffer.prototype.clear=function(){this.context.setTransform(1,0,0,1,0,0),this.context.clearRect(0,0,this.width,this.height)},i.CanvasBuffer.prototype.resize=function(e,t){this.width=this.canvas.width=e,this.height=this.canvas.height=t},i.CanvasBuffer.prototype.destroy=function(){Phaser.CanvasPool.remove(this)},i.CanvasMaskManager=function(){},i.CanvasMaskManager.prototype.constructor=i.CanvasMaskManager,i.CanvasMaskManager.prototype.pushMask=function(e,t){var r=t.context;r.save();var s=e.alpha,o=e.worldTransform,a=t.resolution;r.setTransform(o.a*a,o.b*a,o.c*a,o.d*a,o.tx*a,o.ty*a),i.CanvasGraphics.renderGraphicsMask(e,r),r.clip(),e.worldAlpha=s},i.CanvasMaskManager.prototype.popMask=function(e){e.context.restore()},i.CanvasTinter=function(){},i.CanvasTinter.getTintedTexture=function(e,t){var r=e.tintedTexture||Phaser.CanvasPool.create(this);return i.CanvasTinter.tintMethod(e.texture,t,r),r},i.CanvasTinter.tintWithMultiply=function(e,t,r){var i=r.getContext("2d"),s=e.crop,o=s.width,a=s.height;e.rotated&&(o=a,a=s.width),r.width===o&&r.height===a||(r.width=o,r.height=a),i.clearRect(0,0,o,a),i.fillStyle="#"+("00000"+(0|t).toString(16)).substr(-6),i.fillRect(0,0,o,a),i.globalCompositeOperation="multiply",i.drawImage(e.baseTexture.source,s.x,s.y,o,a,0,0,o,a),i.globalCompositeOperation="destination-atop",i.drawImage(e.baseTexture.source,s.x,s.y,o,a,0,0,o,a)},i.CanvasTinter.tintWithPerPixel=function(e,t,r){var s=r.getContext("2d"),o=e.crop,a=o.width,n=o.height;e.rotated&&(a=n,n=o.width),r.width===a&&r.height===n||(r.width=a,r.height=n),s.globalCompositeOperation="copy",s.drawImage(e.baseTexture.source,o.x,o.y,a,n,0,0,a,n);for(var h=Phaser.Color.hexToRGBArray(t),l=h[0],u=h[1],d=h[2],c=s.getImageData(0,0,a,n),f=c.data,x=0;x<f.length;x+=4)if(f[x+0]*=l,f[x+1]*=u,f[x+2]*=d,!i.CanvasTinter.canHandleAlpha){var p=f[x+3];f[x+0]/=255/p,f[x+1]/=255/p,f[x+2]/=255/p}s.putImageData(c,0,0)},i.CanvasRenderer=function(e,t){if(this.game=e,i.defaultRenderer||(i.defaultRenderer=this),this.type=Phaser.CANVAS,this.resolution=e.resolution,this.clearBeforeRender=e.clearBeforeRender,this.transparent=e.transparent,this.autoResize=!1,this.width=e.width*this.resolution,this.height=e.height*this.resolution,this.view=e.canvas,this.context=this.view.getContext("2d",{alpha:this.transparent}),!this.context)throw new Error("Failed to create a Canvas 2d context.");this.refresh=!0,this.count=0,this.maskManager=new i.CanvasMaskManager,this.renderSession={context:this.context,maskManager:this.maskManager,scaleMode:null,smoothProperty:Phaser.Canvas.getSmoothingPrefix(this.context),roundPixels:t.roundPixels||!1},this.mapBlendModes(),this.resize(this.width,this.height)},i.CanvasRenderer.prototype.constructor=i.CanvasRenderer,i.CanvasRenderer.prototype.render=function(e){this.context.setTransform(1,0,0,1,0,0),this.context.globalAlpha=1,this.renderSession.currentBlendMode=0,this.renderSession.shakeX=this.game.camera._shake.x,this.renderSession.shakeY=this.game.camera._shake.y,this.context.globalCompositeOperation="source-over",navigator.isCocoonJS&&this.view.screencanvas&&(this.context.fillStyle="black",this.context.clear()),this.clearBeforeRender&&(this.transparent?this.context.clearRect(0,0,this.width,this.height):e._bgColor&&(this.context.fillStyle=e._bgColor.rgba,this.context.fillRect(0,0,this.width,this.height))),this.renderDisplayObject(e)},i.CanvasRenderer.prototype.postRender=function(){},i.CanvasRenderer.prototype.setTexturePriority=function(){},i.CanvasRenderer.prototype.destroy=function(e){void 0===e&&(e=!0),e&&this.view.parent&&this.view.parent.removeChild(this.view),this.view=null,this.context=null,this.maskManager=null,this.renderSession=null},i.CanvasRenderer.prototype.resize=function(e,t){this.width=e*this.resolution,this.height=t*this.resolution,this.view.width=this.width,this.view.height=this.height,this.autoResize&&(this.view.style.width=this.width/this.resolution+"px",this.view.style.height=this.height/this.resolution+"px"),this.renderSession.smoothProperty&&(this.context[this.renderSession.smoothProperty]=this.renderSession.scaleMode===i.scaleModes.LINEAR)},i.CanvasRenderer.prototype.renderDisplayObject=function(e,t,r){this.renderSession.context=t||this.context,this.renderSession.resolution=this.resolution,e._renderCanvas(this.renderSession,r)},i.CanvasRenderer.prototype.mapBlendModes=function(){if(!i.blendModesCanvas){var e=[],t=i.blendModes,r=this.game.device.canUseMultiply;e[t.NORMAL]="source-over",e[t.ADD]="lighter",e[t.MULTIPLY]=r?"multiply":"source-over",e[t.SCREEN]=r?"screen":"source-over",e[t.OVERLAY]=r?"overlay":"source-over",e[t.DARKEN]=r?"darken":"source-over",e[t.LIGHTEN]=r?"lighten":"source-over",e[t.COLOR_DODGE]=r?"color-dodge":"source-over",e[t.COLOR_BURN]=r?"color-burn":"source-over",e[t.HARD_LIGHT]=r?"hard-light":"source-over",e[t.SOFT_LIGHT]=r?"soft-light":"source-over",e[t.DIFFERENCE]=r?"difference":"source-over",e[t.EXCLUSION]=r?"exclusion":"source-over",e[t.HUE]=r?"hue":"source-over",e[t.SATURATION]=r?"saturation":"source-over",e[t.COLOR]=r?"color":"source-over",e[t.LUMINOSITY]=r?"luminosity":"source-over",i.blendModesCanvas=e}},i.BaseTexture=function(e,t,r){this.resolution=r||1,this.width=100,this.height=100,this.scaleMode=t||i.scaleModes.DEFAULT,this.hasLoaded=!1,this.source=e,this.premultipliedAlpha=!0,this._glTextures=[],this.mipmap=!1,this.textureIndex=0,this._dirty=[!0,!0,!0,!0],e&&((this.source.complete||this.source.getContext)&&this.source.width&&this.source.height&&(this.hasLoaded=!0,this.width=this.source.naturalWidth||this.source.width,this.height=this.source.naturalHeight||this.source.height,this.dirty()),this.skipRender=!1,this._powerOf2=!1)},i.BaseTexture.prototype.constructor=i.BaseTexture,i.BaseTexture.prototype.forceLoaded=function(e,t){this.hasLoaded=!0,this.width=e,this.height=t,this.dirty()},i.BaseTexture.prototype.destroy=function(){this.source&&Phaser.CanvasPool.removeByCanvas(this.source),this.source=null,this.unloadFromGPU()},i.BaseTexture.prototype.dirty=function(){for(var e=0;e<this._glTextures.length;e++)this._dirty[e]=!0},i.BaseTexture.prototype.unloadFromGPU=function(){this.dirty();for(var e=this._glTextures.length-1;e>=0;e--){var t=this._glTextures[e],r=i.glContexts[e];r&&t&&r.deleteTexture(t)}this._glTextures.length=0,this.dirty()},i.BaseTexture.fromCanvas=function(e,t,r){return 0===e.width&&(e.width=1),0===e.height&&(e.height=1),r=r||1,new i.BaseTexture(e,t,r)},i.TextureSilentFail=!1,i.Texture=function(e,t,r,s){this.noFrame=!1,t||(this.noFrame=!0,t=new i.Rectangle(0,0,1,1)),e instanceof i.Texture&&(e=e.baseTexture),this.baseTexture=e,this.frame=t,this.trim=s,this.valid=!1,this.isTiling=!1,this.requiresUpdate=!1,this.requiresReTint=!1,this._uvs=null,this.width=0,this.height=0,this.crop=r||new i.Rectangle(0,0,1,1),this.rotated=!1,e.hasLoaded&&(this.noFrame&&(t=new i.Rectangle(0,0,e.width,e.height)),this.setFrame(t))},i.Texture.prototype.constructor=i.Texture,i.Texture.prototype.onBaseTextureLoaded=function(){var e=this.baseTexture;this.noFrame&&(this.frame=new i.Rectangle(0,0,e.width,e.height)),this.setFrame(this.frame)},i.Texture.prototype.destroy=function(e){e&&this.baseTexture.destroy(),this.valid=!1},i.Texture.prototype.setFrame=function(e){if(this.noFrame=!1,this.frame=e,this.width=e.width,this.height=e.height,this.crop.x=e.x,this.crop.y=e.y,this.crop.width=e.width,this.crop.height=e.height,this.trim||!(e.x+e.width>this.baseTexture.width||e.y+e.height>this.baseTexture.height))this.valid=e&&e.width&&e.height&&this.baseTexture.source&&this.baseTexture.hasLoaded,this.trim&&(this.width=this.trim.width,this.height=this.trim.height,this.frame.width=this.trim.width,this.frame.height=this.trim.height),this.valid&&this._updateUvs();else{if(!i.TextureSilentFail)throw new Error("Texture Error: frame does not fit inside the base Texture dimensions "+this);this.valid=!1}},i.Texture.prototype._updateUvs=function(){this._uvs||(this._uvs=new i.TextureUvs);var e=this.crop,t=this.baseTexture.width,r=this.baseTexture.height;this._uvs.x0=e.x/t,this._uvs.y0=e.y/r,this._uvs.x1=(e.x+e.width)/t,this._uvs.y1=e.y/r,this._uvs.x2=(e.x+e.width)/t,this._uvs.y2=(e.y+e.height)/r,this._uvs.x3=e.x/t,this._uvs.y3=(e.y+e.height)/r},i.Texture.prototype._updateUvsInverted=function(){this._uvs||(this._uvs=new i.TextureUvs);var e=this.crop,t=this.baseTexture.width,r=this.baseTexture.height;this._uvs.x0=e.x/t,this._uvs.y0=e.y/r,this._uvs.x1=(e.x+e.height)/t,this._uvs.y1=e.y/r,this._uvs.x2=(e.x+e.height)/t,this._uvs.y2=(e.y+e.width)/r,this._uvs.x3=e.x/t,this._uvs.y3=(e.y+e.width)/r},i.Texture.fromCanvas=function(e,t){var r=i.BaseTexture.fromCanvas(e,t);return new i.Texture(r)},i.TextureUvs=function(){this.x0=0,this.y0=0,this.x1=0,this.y1=0,this.x2=0,this.y2=0,this.x3=0,this.y3=0},"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.PIXI=i):"undefined"!=typeof define&&define.amd?define("PIXI",r.PIXI=i):r.PIXI=i,i}).call(this);
//# sourceMappingURL=pixi.map