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) • 80.3 kB
JavaScript
/* Phaser v2.20.2 PIXI Build - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
(function(){var e=this,F=F||{};F.DisplayObject=function(){this.position=new F.Point(0,0),this.scale=new F.Point(1,1),this.pivot=new F.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 F.Point(0,0),this.worldScale=new F.Point(1,1),this.worldRotation=0,this.filterArea=null,this._sr=0,this._cr=1,this._bounds=new F.Rectangle(0,0,0,0),this._currentBounds=null,this._mask=null,this._cacheAsBitmap=!1,this._cacheIsDirty=!1},F.DisplayObject.prototype={constructor:F.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):(r=this.scale.x,s=i=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 c=Math.sqrt(r*r+i*i);this.worldRotation=0<i?Math.acos(r/c):-Math.acos(r/c),this.worldScale.x=c,this.worldScale.y=u/c}else if(s||o){var d=Math.sqrt(s*s+o*o);this.worldRotation=Phaser.Math.HALF_PI-(0<o?Math.acos(-s/d):-Math.acos(s/d)),this.worldScale.x=u/d,this.worldScale.y=d}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 i=this.getLocalBounds(),s=new Phaser.RenderTexture(this.game,0|i.width,0|i.height,r,t,e);return F.DisplayObject._tempMatrix.tx=-i.x,F.DisplayObject._tempMatrix.ty=-i.y,s.render(this,F.DisplayObject._tempMatrix),s},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?F.Sprite.prototype._renderWebGL.call(this._cachedSprite,e):F.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&&F._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 F.Sprite(r),this._cachedSprite.worldTransform=this.worldTransform}var i=this._filters;this._filters=null,this._cachedSprite.filters=i,F.DisplayObject._tempMatrix.tx=-e.x,F.DisplayObject._tempMatrix.ty=-e.y,this._cachedSprite.texture.render(this,F.DisplayObject._tempMatrix,!0),this._cachedSprite.anchor.x=-e.x/e.width,this._cachedSprite.anchor.y=-e.y/e.height,this._filters=i,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)}},F.DisplayObject.prototype.displayObjectUpdateTransform=F.DisplayObject.prototype.updateTransform,Object.defineProperties(F.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)&&(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 i=e[r].passes,s=0;s<i.length;s++)t.push(i[s]);this._filterBlock={target:this,filterPasses:t}}this._filters=e,this.blendMode&&this.blendMode===F.blendModes.MULTIPLY&&(this.blendMode=F.blendModes.NORMAL)}},cacheAsBitmap:{get:function(){return this._cacheAsBitmap},set:function(e){this._cacheAsBitmap!==e&&(e?this._generateCachedSprite():this._destroyCachedSprite(),this._cacheAsBitmap=e)}}}),F.DisplayObjectContainer=function(){F.DisplayObject.call(this),this.children=[],this.ignoreChildInput=!1},F.DisplayObjectContainer.prototype=Object.create(F.DisplayObject.prototype),F.DisplayObjectContainer.prototype.constructor=F.DisplayObjectContainer,F.DisplayObjectContainer.prototype.addChild=function(e){return this.addChildAt(e,this.children.length)},F.DisplayObjectContainer.prototype.addChildAt=function(e,t){if(0<=t&&t<=this.children.length)return e.parent&&e.parent.removeChild(e),(e.parent=this).children.splice(t,0,e),e;throw new Error(e+"addChildAt: The index "+t+" supplied is out of bounds "+this.children.length)},F.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}},F.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},F.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)},F.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]},F.DisplayObjectContainer.prototype.removeChild=function(e){var t=this.children.indexOf(e);if(-1!==t)return this.removeChildAt(t)},F.DisplayObjectContainer.prototype.removeChildAt=function(e){var t=this.getChildAt(e);return t&&(t.parent=void 0,this.children.splice(e,1)),t},F.DisplayObjectContainer.prototype.bringChildToTop=function(e){if(e.parent===this)return this.setChildIndex(e,this.children.length-1)},F.DisplayObjectContainer.prototype.sendChildToBack=function(e){if(e.parent===this)return this.setChildIndex(e,0)},F.DisplayObjectContainer.prototype.removeChildren=function(e,t){void 0===e&&(e=0),void 0===t&&(t=this.children.length);var r=t-e;if(0<r&&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")},F.DisplayObjectContainer.prototype.updateTransform=function(){if(this.visible&&(this.displayObjectUpdateTransform(),!this._cacheAsBitmap))for(var e=0;e<this.children.length;e++)this.children[e].updateTransform()},F.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform=F.DisplayObjectContainer.prototype.updateTransform,F.DisplayObjectContainer.prototype.getBounds=function(e){var t,r=e&&e instanceof F.DisplayObject,i=!0;if(r?i=e instanceof F.DisplayObjectContainer&&e.contains(this):e=this,r){var s=e.worldTransform;for(e.worldTransform=Phaser.identityMatrix,t=0;t<e.children.length;t++)e.children[t].updateTransform()}var o,a,n,h=1/0,l=1/0,u=-1/0,c=-1/0,d=!1;for(t=0;t<this.children.length;t++){this.children[t].visible&&(d=!0,h=h<(o=this.children[t].getBounds()).x?h:o.x,l=l<o.y?l:o.y,u=(a=o.width+o.x)<u?u:a,c=(n=o.height+o.y)<c?c:n)}var f=this._bounds;if(!d){var x=(f=new F.Rectangle).x,p=f.width+f.x,g=f.y,T=f.height+f.y,v=this.worldTransform,m=v.a,E=v.b,_=v.c,S=v.d,y=v.tx,b=v.ty,A=m*p+_*T+y,R=S*T+E*p+b,M=m*x+_*T+y,C=S*T+E*x+b,L=m*x+_*g+y,B=S*g+E*x+b,P=m*p+_*g+y,w=S*g+E*p+b;h=P<(h=L<(h=M<(h=u=A)?M:h)?L:h)?P:h,l=w<(l=B<(l=C<(l=c=R)?C:l)?B:l)?w:l,u=(u=(u=u<M?M:u)<L?L:u)<P?P:u,c=(c=(c=c<C?C:c)<B?B:c)<w?w:c}if(f.x=h,f.y=l,f.width=u-h,f.height=c-l,r)for(e.worldTransform=s,t=0;t<e.children.length;t++)e.children[t].updateTransform();if(!i){var U=e.getBounds();f.x-=U.x,f.y-=U.y}return f},F.DisplayObjectContainer.prototype.getLocalBounds=function(){return this.getBounds(this)},F.DisplayObjectContainer.prototype.contains=function(e){return!!e&&(e===this||this.contains(e.parent))},F.DisplayObjectContainer.prototype._renderWebGL=function(e){var t;if(this.visible&&!(this.alpha<=0))if(this._cacheAsBitmap)this._renderCachedSprite(e);else 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)},F.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(F.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(F.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}}),F.Sprite=function(e){F.DisplayObjectContainer.call(this),this.anchor=new F.Point(F.Sprite.defaultAnchor.x,F.Sprite.defaultAnchor.y),this.texture=e||F.Texture.emptyTexture,this._width=0,this._height=0,this.tint=16777215,this.cachedTint=-1,this.tintedTexture=null,this.blendMode=F.blendModes.NORMAL,this.shader=null,this.exists=!0,this.texture.baseTexture.hasLoaded&&this.onTextureUpdate(),this.renderable=!0},F.Sprite.defaultAnchor={x:0,y:0},F.Sprite.prototype=Object.create(F.DisplayObjectContainer.prototype),F.Sprite.prototype.constructor=F.Sprite,Object.defineProperty(F.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(F.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}}),F.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},F.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)},F.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,c=n.d,d=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;var v=i;i=-s,s=-v}if(c<0){c*=-1;v=o;o=-a,a=-v}g=h*s+d,x=h*i+d,T=c*a+f,p=c*o+f}else{var m=h*s+u*a+d,E=c*a+l*s+f,_=h*i+u*a+d,S=c*a+l*i+f,y=h*i+u*o+d,b=c*o+l*i+f,A=h*s+u*o+d,R=c*o+l*s+f;g=A<(g=y<(g=_<(g=m<g?m:g)?_:g)?y:g)?A:g,T=R<(T=b<(T=S<(T=E<T?E:T)?S:T)?b:T)?R:T,x=(x=(x=(x=x<m?m:x)<_?_:x)<y?y:x)<A?A:x,p=(p=(p=(p=p<E?E:p)<S?S:p)<b?b:p)<R?R:p}var M=this._bounds;return M.x=g,M.width=x-g,M.y=T,M.height=p-T,this._currentBounds=M},F.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},F.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(var 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(s=0;s<this.children.length;s++)this.children[s]._renderWebGL(e,r)}}},F.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=F.blendModesCanvas[e.currentBlendMode]),this._mask&&e.maskManager.pushMask(this._mask,e),this.texture.valid){var i=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===F.scaleModes.LINEAR);var s=this.texture.trim?this.texture.trim.x-this.anchor.x*this.texture.trim.width:this.anchor.x*-this.texture.frame.width,o=this.texture.trim?this.texture.trim.y-this.anchor.y*this.texture.trim.height:this.anchor.y*-this.texture.frame.height,a=r.tx*e.resolution+e.shakeX,n=r.ty*e.resolution+e.shakeY,h=this.texture.crop.width,l=this.texture.crop.height;if(this.texture.rotated){var u=r.a,c=r.b,d=r.c,f=r.d,x=h;a=r.c*l+a,n=r.d*l+n,r.a=6123233995736766e-32*u-d,r.b=6123233995736766e-32*c-f,r.c=u+6123233995736766e-32*d,r.d=c+6123233995736766e-32*f,h=l,l=x}if(e.roundPixels?(e.context.setTransform(r.a,r.b,r.c,r.d,0|a,0|n),s|=0,o|=0):e.context.setTransform(r.a,r.b,r.c,r.d,a,n),s/=i,o/=i,l|=0,(h|=0)&&l){if(16777215!==this.tint)(this.texture.requiresReTint||this.cachedTint!==this.tint)&&(this.tintedTexture=F.CanvasTinter.getTintedTexture(this,this.tint),this.cachedTint=this.tint,this.texture.requiresReTint=!1),e.context.drawImage(this.tintedTexture,0,0,h,l,s,o,h/i,l/i);else{var p=this.texture.crop.x,g=this.texture.crop.y;e.context.drawImage(this.texture.baseTexture.source,p,g,h,l,s,o,h/i,l/i)}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)}}},F.initDefaultShaders=function(){},F.CompileVertexShader=function(e,t){return F._CompileShader(e,t,e.VERTEX_SHADER)},F.CompileFragmentShader=function(e,t){return F._CompileShader(e,t,e.FRAGMENT_SHADER)},F._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)},F.compileProgram=function(e,t,r){var i=F.CompileFragmentShader(e,r),s=F.CompileVertexShader(e,t),o=e.createProgram();return e.attachShader(o,s),e.attachShader(o,i),e.linkProgram(o),e.getProgramParameter(o,e.LINK_STATUS)||(window.console.log(e.getProgramInfoLog(o)),window.console.log("Could not initialise shaders")),o},F.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()},F.PixiShader.prototype.constructor=F.PixiShader,F.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 i=F.compileProgram(e,this.vertexSrc||F.PixiShader.defaultVertexSrc,this.fragmentSrc);e.useProgram(i),this.uSamplerArray=e.getUniformLocation(i,"uSamplerArray[0]"),this.projectionVector=e.getUniformLocation(i,"projectionVector"),this.offsetVector=e.getUniformLocation(i,"offsetVector"),this.dimensions=e.getUniformLocation(i,"dimensions"),this.aVertexPosition=e.getAttribLocation(i,"aVertexPosition"),this.aTextureCoord=e.getAttribLocation(i,"aTextureCoord"),this.colorAttribute=e.getAttribLocation(i,"aColor"),this.aTextureIndex=e.getAttribLocation(i,"aTextureIndex");var s=[],o=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,o),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var a=0;a<this.MAX_TEXTURES;++a)e.activeTexture(e.TEXTURE0+a),e.bindTexture(e.TEXTURE_2D,o),s.push(a);for(var n in e.activeTexture(e.TEXTURE0),e.uniform1iv(this.uSamplerArray,s),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.colorAttribute,this.aTextureIndex],this.uniforms)this.uniforms[n].uniformLocation=e.getUniformLocation(i,n);this.initUniforms(),this.program=i},F.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=F.compileProgram(e,this.vertexSrc||F.PixiShader.defaultVertexSrc,this.fragmentSrc);for(var r in 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],this.uniforms)this.uniforms[r].uniformLocation=e.getUniformLocation(t,r);this.initUniforms(),this.program=t},F.PixiShader.prototype.init=function(e){F._enableMultiTextureToggle&&!e?this.initMultitexShader():this.initDefaultShader()},F.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)}},F.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++}},F.PixiShader.prototype.syncUniforms=function(){var e;this.textureCount=1;var 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]?F.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))},F.PixiShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},F.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;","}"],F.PixiFastShader=function(e){if(this._UID=Phaser._UID++,this.gl=e,this.program=null,F._enableMultiTextureToggle){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()},F.PixiFastShader.prototype.constructor=F.PixiFastShader,F.PixiFastShader.prototype.init=function(){var e=this.gl,t=F.compileProgram(e,this.vertexSrc,this.fragmentSrc);if(e.useProgram(t),this.uSampler=F._enableMultiTextureToggle?e.getUniformLocation(t,"uSamplerArray[0]"):e.getUniformLocation(t,"uSampler"),F._enableMultiTextureToggle){var r=[],i=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var s=0;s<this.MAX_TEXTURES;++s)e.activeTexture(e.TEXTURE0+s),e.bindTexture(e.TEXTURE_2D,i),r.push(s);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},F.PixiFastShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},F.StripShader=function(e){if(this._UID=Phaser._UID++,this.gl=e,this.program=null,F._enableMultiTextureToggle){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()},F.StripShader.prototype.constructor=F.StripShader,F.StripShader.prototype.init=function(){var e=this.gl,t=F.compileProgram(e,this.vertexSrc,this.fragmentSrc);if(e.useProgram(t),this.uSampler=F._enableMultiTextureToggle?e.getUniformLocation(t,"uSamplerArray[0]"):e.getUniformLocation(t,"uSampler"),F._enableMultiTextureToggle){var r=[],i=e.createTexture();e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,i),e.texImage2D(e.TEXTURE_2D,0,e.RGB,1,1,0,e.RGB,e.UNSIGNED_BYTE,null);for(var s=0;s<this.MAX_TEXTURES;++s)e.activeTexture(e.TEXTURE0+s),e.bindTexture(e.TEXTURE_2D,i),r.push(s);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},F.StripShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},F.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()},F.PrimitiveShader.prototype.constructor=F.PrimitiveShader,F.PrimitiveShader.prototype.init=function(){var e=this.gl,t=F.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},F.PrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},F.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()},F.ComplexPrimitiveShader.prototype.constructor=F.ComplexPrimitiveShader,F.ComplexPrimitiveShader.prototype.init=function(){var e=this.gl,t=F.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},F.ComplexPrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},F.glContexts=[],F.instances=[],F._enableMultiTextureToggle=!1,F.WebGLRenderer=function(e,t){this.game=e,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 F.Point,this.offset=new F.Point,this.shaderManager=new F.WebGLShaderManager,this.spriteBatch=new F.WebGLSpriteBatch(e),this.maskManager=new F.WebGLMaskManager,this.filterManager=new F.WebGLFilterManager,this.stencilManager=new F.WebGLStencilManager,this.blendModeManager=new F.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).renderSession.resolution=this.resolution,this.renderSession.roundPixels=t.roundPixels||!1,this.renderSession.maxTextureAvailableSpace=null,this.initContext(),this.mapBlendModes()},F.WebGLRenderer.prototype.constructor=F.WebGLRenderer,F.WebGLRenderer.prototype.initContext=function(){var e=this.view.getContext("webgl",this._contextOptions)||this.view.getContext("experimental-webgl",this._contextOptions);if(!(this.gl=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=F.WebGLRenderer.glContextId++,F.glContexts[this.glContextId]=e,F.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"),i=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),i&&(this.extensions.compression.S3TC=i)},F.WebGLRenderer.prototype.setTexturePriority=function(e){if(F._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,i=r.getParameter(r.MAX_TEXTURE_IMAGE_UNITS),s=r.getParameter(r.MAX_TEXTURE_SIZE),o=this.game.cache._cache.image,a=null,n=0;n<this.currentBatchedTextures.length;n++)(a=this.currentBatchedTextures[n])in o?o[a].base.textureIndex=0:console.warn('setTexturePriority: There is no image "%s" in the image cache.',a);for(var h=s-t(Math.max(this.width,this.height)),l=this.currentBatchedTextures.length=0;l<e.length;++l)if((a=e[l])in o){var u=o[a].base;(h-=t(Math.max(u.width,u.height)))<=0?(u.textureIndex=0,console.warn('setTexturePriority: Image "%s" was given textureIndex=0 because there is no available texture space (%s).',a,h)):u.textureIndex=1+l%(i-1),this.currentBatchedTextures.push(a)}else console.warn('setTexturePriority: There is no image "%s" in the image cache.',a);return this.renderSession.maxTextureAvailableSpace=h,this.currentBatchedTextures}console.warn("setTexturePriority error: Multi Texture support hasn't been enabled in the Phaser Game Config.")},F.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)}},F.WebGLRenderer.prototype.postRender=function(){this.gl.flush()},F.WebGLRenderer.prototype.renderDisplayObject=function(e,t,r,i){this.renderSession.blendModeManager.setBlendMode(F.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,i),this.spriteBatch.end()},F.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},F.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===F.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===F.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===F.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)},F.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===F.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===F.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===F.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)},F.WebGLRenderer.prototype.destroy=function(){F.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),F.instances[this.glContextId]=null,F.WebGLRenderer.glContextId--},F.WebGLRenderer.prototype.mapBlendModes=function(){var e=this.gl;if(!F.blendModesWebGL){var t=[],r=F.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],F.blendModesWebGL=t}},F.WebGLRenderer.prototype.getMaxTextureUnit=function(){var e=this.gl;return e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS)},F.enableMultiTexture=function(){F._enableMultiTextureToggle=!0},F.WebGLRenderer.glContextId=0,F.WebGLRenderer.textureArray=[],F.WebGLBlendModeManager=function(){this.currentBlendMode=99999},F.WebGLBlendModeManager.prototype.constructor=F.WebGLBlendModeManager,F.WebGLBlendModeManager.prototype.setContext=function(e){this.gl=e},F.WebGLBlendModeManager.prototype.setBlendMode=function(e){if(this.currentBlendMode===e)return!1;this.currentBlendMode=e;var t=F.blendModesWebGL[this.currentBlendMode];return t&&this.gl.blendFunc(t[0],t[1]),!0},F.WebGLBlendModeManager.prototype.destroy=function(){this.gl=null},F.WebGLMaskManager=function(){},F.WebGLMaskManager.prototype.constructor=F.WebGLMaskManager,F.WebGLMaskManager.prototype.setContext=function(e){this.gl=e},F.WebGLMaskManager.prototype.pushMask=function(e,t){var r=t.gl;e.dirty&&F.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)},F.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)},F.WebGLMaskManager.prototype.destroy=function(){this.gl=null},F.WebGLStencilManager=function(){this.stencilStack=[],this.reverse=!0,this.count=0},F.WebGLStencilManager.prototype.setContext=function(e){this.gl=e},F.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++},F.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)):(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)},F.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+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)}},F.WebGLStencilManager.prototype.destroy=function(){this.stencilStack=null,this.gl=null},F.WebGLShaderManager=function(){this.maxAttibs=10,this.attribState=[],this.tempAttribState=[];for(var e=0;e<this.maxAttibs;e++)this.attribState[e]=!1;this.stack=[]},F.WebGLShaderManager.prototype.constructor=F.WebGLShaderManager,F.WebGLShaderManager.prototype.setContext=function(e){this.gl=e,this.primitiveShader=new F.PrimitiveShader(e),this.complexPrimitiveShader=new F.ComplexPrimitiveShader(e),this.defaultShader=new F.PixiShader(e),this.fastShader=new F.PixiFastShader(e),this.stripShader=new F.StripShader(e),this.creatureShader=F.CreatureShader?new F.CreatureShader(e):null,this.setShader(this.defaultShader)},F.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))},F.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)},F.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},F.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);for(var i=this.lastIndexCount=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=[],th