phaser-ce
Version:
Phaser CE (Community Edition) is a fast, free and fun HTML5 Game Framework for Desktop and Mobile web browsers.
3 lines (2 loc) • 79.8 kB
JavaScript
/* Phaser v2.9.2 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()},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)}},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.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,v=x.y,T=x.height+x.y,m=this.worldTransform,E=m.a,_=m.b,S=m.c,y=m.d,b=m.tx,A=m.ty,R=E*g+S*T+b,M=y*T+_*g+A,C=E*p+S*T+b,L=y*T+_*p+A,B=E*p+S*v+b,P=y*v+_*p+A,w=E*g+S*v+b,U=y*v+_*g+A;d=R,c=M,u=M,l=w<(l=B<(l=C<(l=R)?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,v=1/0;if(0===l&&0===u){if(h<0){h*=-1;T=i;i=-s,s=-T}if(d<0){d*=-1;var T=o;o=-a,a=-T}g=h*s+c,x=h*i+c,v=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,A=h*s+u*o+c,R=d*o+l*s+f;g=A<(g=y<(g=_<(g=m<g?m:g)?_:g)?y:g)?A:g,v=R<(v=b<(v=S<(v=E<v?E:v)?S:v)?b:v)?R:v,x=A>(x=y>(x=_>(x=m>x?m:x)?_:x)?y:x)?A:x,p=R>(p=b>(p=S>(p=E>p?E:p)?S:p)?b:p)?R:p}var M=this._bounds;return M.x=g,M.width=x-g,M.y=v,M.height=p-v,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<=0||this.texture.crop.height<=0)){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,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,v=this.texture.crop.y;l=Math.floor(l),u=Math.floor(u),e.context.drawImage(this.texture.baseTexture.source,g,v,l,u,o,a,l/s,u/s)}for(T=0;T<this.children.length;T++)this.children[T]._renderCanvas(e);this._mask&&e.maskManager.popMask(e)}else{for(var T=0;T<this.children.length;T++)this.children[T]._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){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.width=e.width,this.height=e.height,this.view=e.canvas,this._contextOptions={alpha:this.transparent,antialias:e.antialias,premultipliedAlpha:this.transparent&&"notMultiplied"!==this.transparent,stencil:!0,preserveDrawingBuffer:this.preserveDrawingBuffer},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=!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.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)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.de