UNPKG

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) 675 kB
/* Phaser v2.20.2 - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */ (function(){var t=this,k=k||{};k.DisplayObject=function(){this.position=new k.Point(0,0),this.scale=new k.Point(1,1),this.pivot=new k.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 k.Point(0,0),this.worldScale=new k.Point(1,1),this.worldRotation=0,this.filterArea=null,this._sr=0,this._cr=1,this._bounds=new k.Rectangle(0,0,0,0),this._currentBounds=null,this._mask=null,this._cacheAsBitmap=!1,this._cacheIsDirty=!1},k.DisplayObject.prototype={constructor:k.DisplayObject,destroy:function(){if(this.children){for(var t=this.children.length;t--;)this.children[t].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(t){if(!t&&!this.parent&&!this.game)return this;var e=this.parent;t?e=t:this.parent||(e=this.game.world);var i,s,n,r,o,a,h=e.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)),i=this._cr*this.scale.x,s=this._sr*this.scale.x,n=-this._sr*this.scale.y,r=this._cr*this.scale.y,o=this.position.x,a=this.position.y,(this.pivot.x||this.pivot.y)&&(o-=this.pivot.x*i+this.pivot.y*n,a-=this.pivot.x*s+this.pivot.y*r),l.a=i*h.a+s*h.c,l.b=i*h.b+s*h.d,l.c=n*h.a+r*h.c,l.d=n*h.b+r*h.d):(i=this.scale.x,n=s=0,r=this.scale.y,o=this.position.x-this.pivot.x*i,a=this.position.y-this.pivot.y*r,l.a=i*h.a,l.b=i*h.b,l.c=r*h.c,l.d=r*h.d),l.tx=o*h.a+a*h.c+h.tx,l.ty=o*h.b+a*h.d+h.ty,i=l.a,s=l.b,n=l.c;var u=i*(r=l.d)-s*n;if(i||s){var c=Math.sqrt(i*i+s*s);this.worldRotation=0<s?Math.acos(i/c):-Math.acos(i/c),this.worldScale.x=c,this.worldScale.y=u/c}else if(n||r){var d=Math.sqrt(n*n+r*r);this.worldRotation=Phaser.Math.HALF_PI-(0<r?Math.acos(-n/d):-Math.acos(n/d)),this.worldScale.x=u/d,this.worldScale.y=d}else this.worldScale.x=0,this.worldScale.y=0;return this.worldAlpha=this.alpha*e.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(t,e,i){var s=this.getLocalBounds(),n=new Phaser.RenderTexture(this.game,0|s.width,0|s.height,i,e,t);return k.DisplayObject._tempMatrix.tx=-s.x,k.DisplayObject._tempMatrix.ty=-s.y,n.render(this,k.DisplayObject._tempMatrix),n},updateCache:function(){return this._generateCachedSprite(),this},toGlobal:function(t){return this.updateTransform(),this.worldTransform.apply(t)},toLocal:function(t,e){return e&&(t=e.toGlobal(t)),this.updateTransform(),this.worldTransform.applyInverse(t)},_renderCachedSprite:function(t){this._cachedSprite.worldAlpha=this.worldAlpha,t.gl?k.Sprite.prototype._renderWebGL.call(this._cachedSprite,t):k.Sprite.prototype._renderCanvas.call(this._cachedSprite,t)},_generateCachedSprite:function(){this._cacheAsBitmap=!1;var t=this.getLocalBounds();if(t.width=Math.max(1,Math.ceil(t.width)),t.height=Math.max(1,Math.ceil(t.height)),this.updateTransform(),this._cachedSprite)this._cachedSprite.texture.resize(t.width,t.height);else{var e=0;this.texture&&this.texture.baseTexture&&k._enableMultiTextureToggle&&(e=this.texture.baseTexture.textureIndex);var i=new Phaser.RenderTexture(this.game,t.width,t.height,void 0,void 0,void 0,void 0,e);this._cachedSprite=new k.Sprite(i),this._cachedSprite.worldTransform=this.worldTransform}var s=this._filters;this._filters=null,this._cachedSprite.filters=s,k.DisplayObject._tempMatrix.tx=-t.x,k.DisplayObject._tempMatrix.ty=-t.y,this._cachedSprite.texture.render(this,k.DisplayObject._tempMatrix,!0),this._cachedSprite.anchor.x=-t.x/t.width,this._cachedSprite.anchor.y=-t.y/t.height,this._filters=s,this._cacheAsBitmap=!0},_destroyCachedSprite:function(){this._cachedSprite&&(this._cachedSprite.texture.destroy(!0),this._cachedSprite=null)},_destroyTintedTexture:function(){this.tintedTexture&&(Phaser.CanvasPool.removeByCanvas(this.tintedTexture),this.tintedTexture=null)}},k.DisplayObject.prototype.displayObjectUpdateTransform=k.DisplayObject.prototype.updateTransform,Object.defineProperties(k.DisplayObject.prototype,{x:{get:function(){return this.position.x},set:function(t){this.position.x=t}},y:{get:function(){return this.position.y},set:function(t){this.position.y=t}},worldVisible:{get:function(){if(this.visible){var t=this.parent;if(!t)return this.visible;do{if(!t.visible)return!1;t=t.parent}while(t);return!0}return!1}},mask:{get:function(){return this._mask},set:function(t){this._mask&&(this._mask.isMask=!1),(this._mask=t)&&(this._mask.isMask=!0)}},filters:{get:function(){return this._filters},set:function(t){if(Array.isArray(t)){for(var e=[],i=0;i<t.length;i++)for(var s=t[i].passes,n=0;n<s.length;n++)e.push(s[n]);this._filterBlock={target:this,filterPasses:e}}this._filters=t,this.blendMode&&this.blendMode===k.blendModes.MULTIPLY&&(this.blendMode=k.blendModes.NORMAL)}},cacheAsBitmap:{get:function(){return this._cacheAsBitmap},set:function(t){this._cacheAsBitmap!==t&&(t?this._generateCachedSprite():this._destroyCachedSprite(),this._cacheAsBitmap=t)}}}),k.DisplayObjectContainer=function(){k.DisplayObject.call(this),this.children=[],this.ignoreChildInput=!1},k.DisplayObjectContainer.prototype=Object.create(k.DisplayObject.prototype),k.DisplayObjectContainer.prototype.constructor=k.DisplayObjectContainer,k.DisplayObjectContainer.prototype.addChild=function(t){return this.addChildAt(t,this.children.length)},k.DisplayObjectContainer.prototype.addChildAt=function(t,e){if(0<=e&&e<=this.children.length)return t.parent&&t.parent.removeChild(t),(t.parent=this).children.splice(e,0,t),t;throw new Error(t+"addChildAt: The index "+e+" supplied is out of bounds "+this.children.length)},k.DisplayObjectContainer.prototype.swapChildren=function(t,e){if(t!==e){var i=this.getChildIndex(t),s=this.getChildIndex(e);if(i<0||s<0)throw new Error("swapChildren: Both the supplied DisplayObjects must be a child of the caller.");this.children[i]=e,this.children[s]=t}},k.DisplayObjectContainer.prototype.getChildIndex=function(t){var e=this.children.indexOf(t);if(-1===e)throw new Error("The supplied DisplayObject must be a child of the caller");return e},k.DisplayObjectContainer.prototype.setChildIndex=function(t,e){if(e<0||e>=this.children.length)throw new Error("The supplied index is out of bounds");var i=this.getChildIndex(t);this.children.splice(i,1),this.children.splice(e,0,t)},k.DisplayObjectContainer.prototype.getChildAt=function(t){if(t<0||t>=this.children.length)throw new Error("getChildAt: Supplied index "+t+" does not exist in the child list, or the supplied DisplayObject must be a child of the caller");return this.children[t]},k.DisplayObjectContainer.prototype.removeChild=function(t){var e=this.children.indexOf(t);if(-1!==e)return this.removeChildAt(e)},k.DisplayObjectContainer.prototype.removeChildAt=function(t){var e=this.getChildAt(t);return e&&(e.parent=void 0,this.children.splice(t,1)),e},k.DisplayObjectContainer.prototype.bringChildToTop=function(t){if(t.parent===this)return this.setChildIndex(t,this.children.length-1)},k.DisplayObjectContainer.prototype.sendChildToBack=function(t){if(t.parent===this)return this.setChildIndex(t,0)},k.DisplayObjectContainer.prototype.removeChildren=function(t,e){void 0===t&&(t=0),void 0===e&&(e=this.children.length);var i=e-t;if(0<i&&i<=e){for(var s=this.children.splice(t,i),n=0;n<s.length;n++){s[n].parent=void 0}return s}if(0===i&&0===this.children.length)return[];throw new Error("removeChildren: Range Error, numeric values are outside the acceptable range")},k.DisplayObjectContainer.prototype.updateTransform=function(){if(this.visible&&(this.displayObjectUpdateTransform(),!this._cacheAsBitmap))for(var t=0;t<this.children.length;t++)this.children[t].updateTransform()},k.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform=k.DisplayObjectContainer.prototype.updateTransform,k.DisplayObjectContainer.prototype.getBounds=function(t){var e,i=t&&t instanceof k.DisplayObject,s=!0;if(i?s=t instanceof k.DisplayObjectContainer&&t.contains(this):t=this,i){var n=t.worldTransform;for(t.worldTransform=Phaser.identityMatrix,e=0;e<t.children.length;e++)t.children[e].updateTransform()}var r,o,a,h=1/0,l=1/0,u=-1/0,c=-1/0,d=!1;for(e=0;e<this.children.length;e++){this.children[e].visible&&(d=!0,h=h<(r=this.children[e].getBounds()).x?h:r.x,l=l<r.y?l:r.y,u=(o=r.width+r.x)<u?u:o,c=(a=r.height+r.y)<c?c:a)}var p=this._bounds;if(!d){var f=(p=new k.Rectangle).x,g=p.width+p.x,m=p.y,y=p.height+p.y,v=this.worldTransform,x=v.a,b=v.b,_=v.c,T=v.d,w=v.tx,C=v.ty,S=x*g+_*y+w,P=T*y+b*g+C,E=x*f+_*y+w,A=T*y+b*f+C,M=x*f+_*m+w,R=T*m+b*f+C,L=x*g+_*m+w,O=T*m+b*g+C;h=L<(h=M<(h=E<(h=u=S)?E:h)?M:h)?L:h,l=O<(l=R<(l=A<(l=c=P)?A:l)?R:l)?O:l,u=(u=(u=u<E?E:u)<M?M:u)<L?L:u,c=(c=(c=c<A?A:c)<R?R:c)<O?O:c}if(p.x=h,p.y=l,p.width=u-h,p.height=c-l,i)for(t.worldTransform=n,e=0;e<t.children.length;e++)t.children[e].updateTransform();if(!s){var I=t.getBounds();p.x-=I.x,p.y-=I.y}return p},k.DisplayObjectContainer.prototype.getLocalBounds=function(){return this.getBounds(this)},k.DisplayObjectContainer.prototype.contains=function(t){return!!t&&(t===this||this.contains(t.parent))},k.DisplayObjectContainer.prototype._renderWebGL=function(t){var e;if(this.visible&&!(this.alpha<=0))if(this._cacheAsBitmap)this._renderCachedSprite(t);else if(this._mask||this._filters){for(this._filters&&(t.spriteBatch.flush(),t.filterManager.pushFilter(this._filterBlock)),this._mask&&(t.spriteBatch.stop(),t.maskManager.pushMask(this.mask,t),t.spriteBatch.start()),e=0;e<this.children.length;e++)this.children[e]._renderWebGL(t);t.spriteBatch.stop(),this._mask&&t.maskManager.popMask(this._mask,t),this._filters&&t.filterManager.popFilter(),t.spriteBatch.start()}else for(e=0;e<this.children.length;e++)this.children[e]._renderWebGL(t)},k.DisplayObjectContainer.prototype._renderCanvas=function(t){if(!1!==this.visible&&0!==this.alpha)if(this._cacheAsBitmap)this._renderCachedSprite(t);else{this._mask&&t.maskManager.pushMask(this._mask,t);for(var e=0;e<this.children.length;e++)this.children[e]._renderCanvas(t);this._mask&&t.maskManager.popMask(t)}},Object.defineProperty(k.DisplayObjectContainer.prototype,"width",{get:function(){return this.getLocalBounds().width*this.scale.x},set:function(t){var e=this.getLocalBounds().width;this.scale.x=0!==e?t/e:1,this._width=t}}),Object.defineProperty(k.DisplayObjectContainer.prototype,"height",{get:function(){return this.getLocalBounds().height*this.scale.y},set:function(t){var e=this.getLocalBounds().height;this.scale.y=0!==e?t/e:1,this._height=t}}),k.Sprite=function(t){k.DisplayObjectContainer.call(this),this.anchor=new k.Point(k.Sprite.defaultAnchor.x,k.Sprite.defaultAnchor.y),this.texture=t||k.Texture.emptyTexture,this._width=0,this._height=0,this.tint=16777215,this.cachedTint=-1,this.tintedTexture=null,this.blendMode=k.blendModes.NORMAL,this.shader=null,this.exists=!0,this.texture.baseTexture.hasLoaded&&this.onTextureUpdate(),this.renderable=!0},k.Sprite.defaultAnchor={x:0,y:0},k.Sprite.prototype=Object.create(k.DisplayObjectContainer.prototype),k.Sprite.prototype.constructor=k.Sprite,Object.defineProperty(k.Sprite.prototype,"width",{get:function(){return this.scale.x*this.texture.frame.width},set:function(t){this.scale.x=t/this.texture.frame.width,this._width=t}}),Object.defineProperty(k.Sprite.prototype,"height",{get:function(){return this.scale.y*this.texture.frame.height},set:function(t){this.scale.y=t/this.texture.frame.height,this._height=t}}),k.Sprite.prototype.setTexture=function(t,e){e&&this.texture.baseTexture.destroy(),this.texture.baseTexture.skipRender=!1,this.texture=t,this.texture.valid=!0,this.cachedTint=-1},k.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)},k.Sprite.prototype.getBounds=function(t){var e=this.texture.frame.width,i=this.texture.frame.height,s=e*(1-this.anchor.x),n=e*-this.anchor.x,r=i*(1-this.anchor.y),o=i*-this.anchor.y,a=t||this.worldTransform,h=a.a,l=a.b,u=a.c,c=a.d,d=a.tx,p=a.ty,f=-1/0,g=-1/0,m=1/0,y=1/0;if(0===l&&0===u){if(h<0){h*=-1;var v=s;s=-n,n=-v}if(c<0){c*=-1;v=r;r=-o,o=-v}m=h*n+d,f=h*s+d,y=c*o+p,g=c*r+p}else{var x=h*n+u*o+d,b=c*o+l*n+p,_=h*s+u*o+d,T=c*o+l*s+p,w=h*s+u*r+d,C=c*r+l*s+p,S=h*n+u*r+d,P=c*r+l*n+p;m=S<(m=w<(m=_<(m=x<m?x:m)?_:m)?w:m)?S:m,y=P<(y=C<(y=T<(y=b<y?b:y)?T:y)?C:y)?P:y,f=(f=(f=(f=f<x?x:f)<_?_:f)<w?w:f)<S?S:f,g=(g=(g=(g=g<b?b:g)<T?T:g)<C?C:g)<P?P:g}var E=this._bounds;return E.x=m,E.width=f-m,E.y=y,E.height=g-y,this._currentBounds=E},k.Sprite.prototype.getLocalBounds=function(){var t=this.worldTransform;this.worldTransform=Phaser.identityMatrix;for(var e=0;e<this.children.length;e++)this.children[e].updateTransform();var i=this.getBounds();for(this.worldTransform=t,e=0;e<this.children.length;e++)this.children[e].updateTransform();return i},k.Sprite.prototype._renderWebGL=function(t,e){if(this.visible&&!(this.alpha<=0)&&this.renderable){var i=this.worldTransform;if(e&&(i=e),this._mask||this._filters){var s=t.spriteBatch;this._filters&&(s.flush(),t.filterManager.pushFilter(this._filterBlock)),this._mask&&(s.stop(),t.maskManager.pushMask(this.mask,t),s.start()),s.render(this);for(var n=0;n<this.children.length;n++)this.children[n]._renderWebGL(t);s.stop(),this._mask&&t.maskManager.popMask(this._mask,t),this._filters&&t.filterManager.popFilter(),s.start()}else{t.spriteBatch.render(this);for(n=0;n<this.children.length;n++)this.children[n]._renderWebGL(t,i)}}},k.Sprite.prototype._renderCanvas=function(t,e){if(!(!this.visible||0===this.alpha||!this.renderable||this.texture.crop.width<1||this.texture.crop.height<1)){var i=this.worldTransform;if(e&&(i=e),this.blendMode!==t.currentBlendMode&&(t.currentBlendMode=this.blendMode,t.context.globalCompositeOperation=k.blendModesCanvas[t.currentBlendMode]),this._mask&&t.maskManager.pushMask(this._mask,t),this.texture.valid){var s=this.texture.baseTexture.resolution/t.resolution;t.context.globalAlpha=this.worldAlpha,t.smoothProperty&&t.scaleMode!==this.texture.baseTexture.scaleMode&&(t.scaleMode=this.texture.baseTexture.scaleMode,t.context[t.smoothProperty]=t.scaleMode===k.scaleModes.LINEAR);var n=this.texture.trim?this.texture.trim.x-this.anchor.x*this.texture.trim.width:this.anchor.x*-this.texture.frame.width,r=this.texture.trim?this.texture.trim.y-this.anchor.y*this.texture.trim.height:this.anchor.y*-this.texture.frame.height,o=i.tx*t.resolution+t.shakeX,a=i.ty*t.resolution+t.shakeY,h=this.texture.crop.width,l=this.texture.crop.height;if(this.texture.rotated){var u=i.a,c=i.b,d=i.c,p=i.d,f=h;o=i.c*l+o,a=i.d*l+a,i.a=6123233995736766e-32*u-d,i.b=6123233995736766e-32*c-p,i.c=u+6123233995736766e-32*d,i.d=c+6123233995736766e-32*p,h=l,l=f}if(t.roundPixels?(t.context.setTransform(i.a,i.b,i.c,i.d,0|o,0|a),n|=0,r|=0):t.context.setTransform(i.a,i.b,i.c,i.d,o,a),n/=s,r/=s,l|=0,(h|=0)&&l){if(16777215!==this.tint)(this.texture.requiresReTint||this.cachedTint!==this.tint)&&(this.tintedTexture=k.CanvasTinter.getTintedTexture(this,this.tint),this.cachedTint=this.tint,this.texture.requiresReTint=!1),t.context.drawImage(this.tintedTexture,0,0,h,l,n,r,h/s,l/s);else{var g=this.texture.crop.x,m=this.texture.crop.y;t.context.drawImage(this.texture.baseTexture.source,g,m,h,l,n,r,h/s,l/s)}for(y=0;y<this.children.length;y++)this.children[y]._renderCanvas(t);this._mask&&t.maskManager.popMask(t)}}else{for(var y=0;y<this.children.length;y++)this.children[y]._renderCanvas(t);this._mask&&t.maskManager.popMask(t)}}},k.initDefaultShaders=function(){},k.CompileVertexShader=function(t,e){return k._CompileShader(t,e,t.VERTEX_SHADER)},k.CompileFragmentShader=function(t,e){return k._CompileShader(t,e,t.FRAGMENT_SHADER)},k._CompileShader=function(t,e,i){var s=e;Array.isArray(e)&&(s=e.join("\n"));var n=t.createShader(i);return t.shaderSource(n,s),t.compileShader(n),t.getShaderParameter(n,t.COMPILE_STATUS)?n:(window.console.log(t.getShaderInfoLog(n)),null)},k.compileProgram=function(t,e,i){var s=k.CompileFragmentShader(t,i),n=k.CompileVertexShader(t,e),r=t.createProgram();return t.attachShader(r,n),t.attachShader(r,s),t.linkProgram(r),t.getProgramParameter(r,t.LINK_STATUS)||(window.console.log(t.getProgramInfoLog(r)),window.console.log("Could not initialise shaders")),r},k.PixiShader=function(t){this._UID=Phaser._UID++,this.gl=t,this.program=null,this.fragmentSrc=null,this.textureCount=0,this.firstRun=!0,this.dirty=!0,this.attributes=[],this.init()},k.PixiShader.prototype.constructor=k.PixiShader,k.PixiShader.prototype.initMultitexShader=function(){var t=this.gl;this.MAX_TEXTURES=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);for(var e="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;return;}\n",i=1;i<this.MAX_TEXTURES;++i)e+="\tif (vTextureIndex == "+i+".0) {gl_FragColor = texture2D(uSamplerArray["+i+"], 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) {",e," if(vTextureIndex >= "+this.MAX_TEXTURES+".0) { gl_FragColor = BLUE;return;}"," if(isnan(vTextureIndex)) { gl_FragColor = RED;return;}","}"];var s=k.compileProgram(t,this.vertexSrc||k.PixiShader.defaultVertexSrc,this.fragmentSrc);t.useProgram(s),this.uSamplerArray=t.getUniformLocation(s,"uSamplerArray[0]"),this.projectionVector=t.getUniformLocation(s,"projectionVector"),this.offsetVector=t.getUniformLocation(s,"offsetVector"),this.dimensions=t.getUniformLocation(s,"dimensions"),this.aVertexPosition=t.getAttribLocation(s,"aVertexPosition"),this.aTextureCoord=t.getAttribLocation(s,"aTextureCoord"),this.colorAttribute=t.getAttribLocation(s,"aColor"),this.aTextureIndex=t.getAttribLocation(s,"aTextureIndex");var n=[],r=t.createTexture();t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,r),t.texImage2D(t.TEXTURE_2D,0,t.RGB,1,1,0,t.RGB,t.UNSIGNED_BYTE,null);for(var o=0;o<this.MAX_TEXTURES;++o)t.activeTexture(t.TEXTURE0+o),t.bindTexture(t.TEXTURE_2D,r),n.push(o);for(var a in t.activeTexture(t.TEXTURE0),t.uniform1iv(this.uSamplerArray,n),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.colorAttribute,this.aTextureIndex],this.uniforms)this.uniforms[a].uniformLocation=t.getUniformLocation(s,a);this.initUniforms(),this.program=s},k.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 t=this.gl,e=k.compileProgram(t,this.vertexSrc||k.PixiShader.defaultVertexSrc,this.fragmentSrc);for(var i in t.useProgram(e),this.uSampler=t.getUniformLocation(e,"uSampler"),this.projectionVector=t.getUniformLocation(e,"projectionVector"),this.offsetVector=t.getUniformLocation(e,"offsetVector"),this.dimensions=t.getUniformLocation(e,"dimensions"),this.aVertexPosition=t.getAttribLocation(e,"aVertexPosition"),this.aTextureCoord=t.getAttribLocation(e,"aTextureCoord"),this.colorAttribute=t.getAttribLocation(e,"aColor"),this.aTextureIndex=t.getAttribLocation(e,"aTextureIndex"),-1===this.colorAttribute&&(this.colorAttribute=2),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.colorAttribute,this.aTextureIndex],this.uniforms)this.uniforms[i].uniformLocation=t.getUniformLocation(e,i);this.initUniforms(),this.program=e},k.PixiShader.prototype.init=function(t){k._enableMultiTextureToggle&&!t?this.initMultitexShader():this.initDefaultShader()},k.PixiShader.prototype.initUniforms=function(){this.textureCount=1;var t,e=this.gl;for(var i in this.uniforms){var s=(t=this.uniforms[i]).type;"sampler2D"===s?(t._init=!1,null!==t.value&&this.initSampler2D(t)):"mat2"===s||"mat3"===s||"mat4"===s?(t.glMatrix=!0,t.glValueLength=1,"mat2"===s?t.glFunc=e.uniformMatrix2fv:"mat3"===s?t.glFunc=e.uniformMatrix3fv:"mat4"===s&&(t.glFunc=e.uniformMatrix4fv)):(t.glFunc=e["uniform"+s],t.glValueLength="2f"===s||"2i"===s?2:"3f"===s||"3i"===s?3:"4f"===s||"4i"===s?4:1)}},k.PixiShader.prototype.initSampler2D=function(t){if(t.value&&t.value.baseTexture&&t.value.baseTexture.hasLoaded){var e=this.gl;if(e.activeTexture(e.TEXTURE0+this.textureCount),e.bindTexture(e.TEXTURE_2D,t.value.baseTexture._glTextures[e.id]),t.textureData){var i=t.textureData,s=i.magFilter?i.magFilter:e.LINEAR,n=i.minFilter?i.minFilter:e.LINEAR,r=i.wrapS?i.wrapS:e.CLAMP_TO_EDGE,o=i.wrapT?i.wrapT:e.CLAMP_TO_EDGE,a=i.luminance?e.LUMINANCE:e.RGBA;if(i.repeat&&(r=e.REPEAT,o=e.REPEAT),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!!i.flipY),i.width){var h=i.width?i.width:512,l=i.height?i.height:2,u=i.border?i.border:0;e.texImage2D(e.TEXTURE_2D,0,a,h,l,u,a,e.UNSIGNED_BYTE,null)}else e.texImage2D(e.TEXTURE_2D,0,a,e.RGBA,e.UNSIGNED_BYTE,t.value.baseTexture.source);e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,o)}e.uniform1i(t.uniformLocation,this.textureCount),t._init=!0,this.textureCount++}},k.PixiShader.prototype.syncUniforms=function(){var t;this.textureCount=1;var e=this.gl;for(var i in this.uniforms)1===(t=this.uniforms[i]).glValueLength?!0===t.glMatrix?t.glFunc.call(e,t.uniformLocation,t.transpose,t.value):t.glFunc.call(e,t.uniformLocation,t.value):2===t.glValueLength?t.glFunc.call(e,t.uniformLocation,t.value.x,t.value.y):3===t.glValueLength?t.glFunc.call(e,t.uniformLocation,t.value.x,t.value.y,t.value.z):4===t.glValueLength?t.glFunc.call(e,t.uniformLocation,t.value.x,t.value.y,t.value.z,t.value.w):"sampler2D"===t.type&&(t._init?(e.activeTexture(e["TEXTURE"+this.textureCount]),t.value.baseTexture._dirty[e.id]?k.instances[e.id].updateTexture(t.value.baseTexture):e.bindTexture(e.TEXTURE_2D,t.value.baseTexture._glTextures[e.id]),e.uniform1i(t.uniformLocation,this.textureCount),this.textureCount++):this.initSampler2D(t))},k.PixiShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},k.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;","}"],k.PixiFastShader=function(t){if(this._UID=Phaser._UID++,this.gl=t,this.program=null,k._enableMultiTextureToggle){t=this.gl;this.MAX_TEXTURES=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);for(var e="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;return;}\n",i=1;i<this.MAX_TEXTURES;++i)e+="\tif (vTextureIndex == "+i+".0) { gl_FragColor = texture2D(uSamplerArray["+i+"], 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) {",e," 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()},k.PixiFastShader.prototype.constructor=k.PixiFastShader,k.PixiFastShader.prototype.init=function(){var t=this.gl,e=k.compileProgram(t,this.vertexSrc,this.fragmentSrc);if(t.useProgram(e),this.uSampler=k._enableMultiTextureToggle?t.getUniformLocation(e,"uSamplerArray[0]"):t.getUniformLocation(e,"uSampler"),k._enableMultiTextureToggle){var i=[],s=t.createTexture();t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,s),t.texImage2D(t.TEXTURE_2D,0,t.RGB,1,1,0,t.RGB,t.UNSIGNED_BYTE,null);for(var n=0;n<this.MAX_TEXTURES;++n)t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,s),i.push(n);t.activeTexture(t.TEXTURE0),t.uniform1iv(this.uSampler,i)}this.projectionVector=t.getUniformLocation(e,"projectionVector"),this.offsetVector=t.getUniformLocation(e,"offsetVector"),this.dimensions=t.getUniformLocation(e,"dimensions"),this.uMatrix=t.getUniformLocation(e,"uMatrix"),this.aVertexPosition=t.getAttribLocation(e,"aVertexPosition"),this.aPositionCoord=t.getAttribLocation(e,"aPositionCoord"),this.aScale=t.getAttribLocation(e,"aScale"),this.aRotation=t.getAttribLocation(e,"aRotation"),this.aTextureCoord=t.getAttribLocation(e,"aTextureCoord"),this.colorAttribute=t.getAttribLocation(e,"aColor"),this.aTextureIndex=t.getAttribLocation(e,"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=e},k.PixiFastShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},k.StripShader=function(t){if(this._UID=Phaser._UID++,this.gl=t,this.program=null,k._enableMultiTextureToggle){t=this.gl;this.MAX_TEXTURES=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);for(var e="\tif (vTextureIndex == 0.0) { gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord);return;}\n",i=1;i<this.MAX_TEXTURES;++i)e+="\tif (vTextureIndex == "+i+".0) { gl_FragColor = texture2D(uSamplerArray["+i+"], 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) {",e," 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()},k.StripShader.prototype.constructor=k.StripShader,k.StripShader.prototype.init=function(){var t=this.gl,e=k.compileProgram(t,this.vertexSrc,this.fragmentSrc);if(t.useProgram(e),this.uSampler=k._enableMultiTextureToggle?t.getUniformLocation(e,"uSamplerArray[0]"):t.getUniformLocation(e,"uSampler"),k._enableMultiTextureToggle){var i=[],s=t.createTexture();t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,s),t.texImage2D(t.TEXTURE_2D,0,t.RGB,1,1,0,t.RGB,t.UNSIGNED_BYTE,null);for(var n=0;n<this.MAX_TEXTURES;++n)t.activeTexture(t.TEXTURE0+n),t.bindTexture(t.TEXTURE_2D,s),i.push(n);t.activeTexture(t.TEXTURE0),t.uniform1iv(this.uSampler,i)}this.projectionVector=t.getUniformLocation(e,"projectionVector"),this.offsetVector=t.getUniformLocation(e,"offsetVector"),this.colorAttribute=t.getAttribLocation(e,"aColor"),this.aTextureIndex=t.getAttribLocation(e,"aTextureIndex"),this.aVertexPosition=t.getAttribLocation(e,"aVertexPosition"),this.aTextureCoord=t.getAttribLocation(e,"aTextureCoord"),this.attributes=[this.aVertexPosition,this.aTextureCoord,this.aTextureIndex],this.translationMatrix=t.getUniformLocation(e,"translationMatrix"),this.alpha=t.getUniformLocation(e,"alpha"),this.program=e},k.StripShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},k.PrimitiveShader=function(t){this._UID=Phaser._UID++,this.gl=t,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()},k.PrimitiveShader.prototype.constructor=k.PrimitiveShader,k.PrimitiveShader.prototype.init=function(){var t=this.gl,e=k.compileProgram(t,this.vertexSrc,this.fragmentSrc);t.useProgram(e),this.projectionVector=t.getUniformLocation(e,"projectionVector"),this.offsetVector=t.getUniformLocation(e,"offsetVector"),this.tintColor=t.getUniformLocation(e,"tint"),this.flipY=t.getUniformLocation(e,"flipY"),this.aVertexPosition=t.getAttribLocation(e,"aVertexPosition"),this.colorAttribute=t.getAttribLocation(e,"aColor"),this.attributes=[this.aVertexPosition,this.colorAttribute],this.translationMatrix=t.getUniformLocation(e,"translationMatrix"),this.alpha=t.getUniformLocation(e,"alpha"),this.program=e},k.PrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attributes=null},k.ComplexPrimitiveShader=function(t){this._UID=Phaser._UID++,this.gl=t,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()},k.ComplexPrimitiveShader.prototype.constructor=k.ComplexPrimitiveShader,k.ComplexPrimitiveShader.prototype.init=function(){var t=this.gl,e=k.compileProgram(t,this.vertexSrc,this.fragmentSrc);t.useProgram(e),this.projectionVector=t.getUniformLocation(e,"projectionVector"),this.offsetVector=t.getUniformLocation(e,"offsetVector"),this.tintColor=t.getUniformLocation(e,"tint"),this.color=t.getUniformLocation(e,"color"),this.flipY=t.getUniformLocation(e,"flipY"),this.aVertexPosition=t.getAttribLocation(e,"aVertexPosition"),this.attributes=[this.aVertexPosition,this.colorAttribute],this.translationMatrix=t.getUniformLocation(e,"translationMatrix"),this.alpha=t.getUniformLocation(e,"alpha"),this.program=e},k.ComplexPrimitiveShader.prototype.destroy=function(){this.gl.deleteProgram(this.program),this.uniforms=null,this.gl=null,this.attribute=null},k.glContexts=[],k.instances=[],k._enableMultiTextureToggle=!1,k.WebGLRenderer=function(t,e){this.game=t,this.extensions={},this.type=Phaser.WEBGL,this.resolution=t.resolution,this.transparent=t.transparent,this.autoResize=!1,this.preserveDrawingBuffer=t.preserveDrawingBuffer,this.clearBeforeRender=t.clearBeforeRender,this.powerPreference=t.powerPreference,this.width=t.width,this.height=t.height,this.view=t.canvas,this._contextOptions={alpha:this.transparent,antialias:t.antialias,failIfMajorPerformanceCaveat:e.failIfMajorPerformanceCaveat,premultipliedAlpha:this.transparent&&"notMultiplied"!==this.transparent,stencil:!0,preserveDrawingBuffer:this.preserveDrawingBuffer,powerPreference:t.powerPreference},this.projection=new k.Point,this.offset=new k.Point,this.shaderManager=new k.WebGLShaderManager,this.spriteBatch=new k.WebGLSpriteBatch(t),this.maskManager=new k.WebGLMaskManager,this.filterManager=new k.WebGLFilterManager,this.stencilManager=new k.WebGLStencilManager,this.blendModeManager=new k.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=e.roundPixels||!1,this.renderSession.maxTextureAvailableSpace=null,this.initContext(),this.mapBlendModes()},k.WebGLRenderer.prototype.constructor=k.WebGLRenderer,k.WebGLRenderer.prototype.initContext=function(){var t=this.view.getContext("webgl",this._contextOptions)||this.view.getContext("experimental-webgl",this._contextOptions);if(!(this.gl=t))throw new Error("This browser does not support webGL. Try using the canvas renderer");this.maxTextures=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS),this.maxTextureSize=this.gl.getParameter(t.MAX_TEXTURE_SIZE),this.glContextId=t.id=k.WebGLRenderer.glContextId++,k.glContexts[this.glContextId]=t,k.instances[this.glContextId]=this,t.disable(t.DEPTH_TEST),t.disable(t.CULL_FACE),t.enable(t.BLEND),this.shaderManager.setContext(t),this.spriteBatch.setContext(t),this.maskManager.setContext(t),this.filterManager.setContext(t),this.blendModeManager.setContext(t),this.stencilManager.setContext(t),this.renderSession.gl=this.gl,this.resize(this.width,this.height),this.extensions.compression={};var e=t.getExtension("WEBGL_compressed_texture_etc1")||t.getExtension("WEBKIT_WEBGL_compressed_texture_etc1"),i=t.getExtension("WEBGL_compressed_texture_pvrtc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),s=t.getExtension("WEBGL_compressed_texture_s3tc")||t.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc");e&&(this.extensions.compression.ETC1=e),i&&(this.extensions.compression.PVRTC=i),s&&(this.extensions.compression.S3TC=s)},k.WebGLRenderer.prototype.setTexturePriority=function(t){if(k._enableMultiTextureToggle){for(var e=function(t){return--t,t|=t>>1,t|=t>>2,t|=t>>4,t|=t>>8,t|=t>>16,++t},i=this.gl,s=i.getParameter(i.MAX_TEXTURE_IMAGE_UNITS),n=i.getParameter(i.MAX_TEXTURE_SIZE),r=this.game.cache._cache.image,o=null,a=0;a<this.currentBatchedTextures.length;a++)(o=this.currentBatchedTextures[a])in r?r[o].base.textureIndex=0:console.warn('setTexturePriority: There is no image "%s" in the image cache.',o);for(var h=n-e(Math.max(this.width,this.height)),l=this.currentBatchedTextures.length=0;l<t.length;++l)if((o=t[l])in r){var u=r[o].base;(h-=e(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).',o,h)):u.textureIndex=1+l%(s-1),this.currentBatchedTextures.push(o)}else console.warn('setTexturePriority: There is no image "%s" in the image cache.',o);return this.renderSession.maxTextureAvailableSpace=h,this.currentBatchedTextures}console.warn("setTexturePriority error: Multi Texture support hasn't been enabled in the Phaser Game Config.")},k.WebGLRenderer.prototype.render=function(t){if(!this.contextLost){var e=this.gl;e.viewport(0,0,this.width,this.height),e.bindFramebuffer(e.FRAMEBUFFER,null),this.game.clearBeforeRender&&(e.clearColor(t._bgColor.r,t._bgColor.g,t._bgColor.b,t._bgColor.a),e.clear(e.COLOR_BUFFER_BIT)),this.offset.x=this.game.camera._shake.x,this.offset.y=this.game.camera._shake.y,this.renderDisplayObject(t,this.projection)}},k.WebGLRenderer.prototype.postRender=function(){this.gl.flush()},k.WebGLRenderer.prototype.renderDisplayObject=function(t,e,i,s){this.renderSession.blendModeManager.setBlendMode(k.blendModes.NORMAL),this.renderSession.drawCount=0,this.renderSession.flipY=i?-1:1,this.renderSession.projection=e,this.renderSession.offset=this.offset,this.spriteBatch.begin(this.renderSession),this.filterManager.begin(this.renderSession,i),t._renderWebGL(this.renderSession,s),this.spriteBatch.end()},k.WebGLRenderer.prototype.resize=function(t,e){this.width=t*this.resolution,this.height=e*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},k.WebGLRenderer.prototype.updateCompressedTexture=function(t){if(!t.hasLoaded)return!1;var e=this.gl,i=t.source;return t._glTextures[e.id]||(t._glTextures[e.id]=e.createTexture()),e.activeTexture(e.TEXTURE0+t.textureIndex),e.bindTexture(e.TEXTURE_2D,t._glTextures[e.id]),e.compressedTexImage2D(e.TEXTURE_2D,0,i.glExtensionFormat,i.width,i.height,0,i.textureData),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR:e.NEAREST),t.mipmap&&Phaser.Math.isPowerOfTwo(t.width,t.height)?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR_MIPMAP_LINEAR:e.NEAREST_MIPMAP_NEAREST),e.generateMipmap(e.TEXTURE_2D)):e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR:e.NEAREST),t._powerOf2?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT)):(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)),!(t._dirty[e.id]=!1)},k.WebGLRenderer.prototype.updateTexture=function(t){if(!t.hasLoaded||!t.source)return!1;if(t.source.compressionAlgorithm)return this.updateCompressedTexture(t);var e=this.gl;return t._glTextures[e.id]||(t._glTextures[e.id]=e.createTexture()),e.activeTexture(e.TEXTURE0+t.textureIndex),e.bindTexture(e.TEXTURE_2D,t._glTextures[e.id]),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultipliedAlpha),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t.source),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR:e.NEAREST),t.mipmap&&Phaser.Math.isPowerOfTwo(t.width,t.height)?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR_MIPMAP_LINEAR:e.NEAREST_MIPMAP_NEAREST),e.generateMipmap(e.TEXTURE_2D)):e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,t.scaleMode===k.scaleModes.LINEAR?e.LINEAR:e.NEAREST),t._powerOf2?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT)):(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)),!(t._dirty[e.id]=!1)},k.WebGLRenderer.prototype.destroy=function(){k.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),k.instances[this.glContextId]=null,k.WebGLRenderer.glContextId--},k.WebGLRenderer.prototype.mapBlendModes=function(){var t=this.gl;if(!k.blendModesWebGL){var e=[],i=k.blendModes;e[i.NORMAL]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.ADD]=[t.SRC_ALPHA,t.DST_ALPHA],e[i.MULTIPLY]=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA],e[i.SCREEN]=[t.SRC_ALPHA,t.ONE],e[i.OVERLAY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.DARKEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.LIGHTEN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.COLOR_DODGE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.COLOR_BURN]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.HARD_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.SOFT_LIGHT]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.DIFFERENCE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.EXCLUSION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.HUE]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.SATURATION]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.COLOR]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e[i.LUMINOSITY]=[t.ONE,t.ONE_MINUS_SRC_ALPHA],k.blendModesWebGL=e}},k.WebGLRenderer.prototype.getMaxTextureUnit=function(){var t=this.gl;return t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS)},k.enableMultiTexture=function(){k._enableMultiTextureToggle=!0},k.WebGLRenderer.glContextId=0,k.WebGLRenderer.textureArray=[],k.WebGLBlendModeManager=function(){this.currentBlendMode=99999},k.WebGLBlendModeManager.prototype.constructor=k.WebGLBlendModeManager,k.WebGLBlendModeManager.prototype.setContext=function(t){this.gl=t},k.WebGLBlendModeManager.prototype.setBlendMode=function(t){if(this.currentBlendMode===t)return!1;this.currentBlendMode=t;var e=k.blendModesWebGL[this.currentBlendMode];return e&&this.gl.blendFunc(e[0],e[1]),!0},k.WebGLBlendModeManager.prototype.destroy=function(){this.gl=null},k.WebGLMaskManager=function(){},k.WebGLMaskManager.prototype.constructor=k.WebGLMaskManager,k.WebGLMaskManager.prototype.setContext=function(t){this.gl=t},k.WebGLMaskManager.prototype.pushMask=function(t,e){var i=e.gl;t.dirty&&k.WebGLGraphics.updateGraphics(t,i),void 0!==t._webGL[i.id]&&void 0!==t._webGL[i.id].data&&0!==t._webGL[i.id].data.length&&e.stencilManager.pushStencil(t,t._webGL[i.id].data[0],e)},k.WebGLMaskManager.prototype.popMask=function(t,e){var i=this.gl;void 0!==t._webGL[i.id]&&void 0!==t._webGL[i.id].data&&0!==t._webGL[i.id].data.length&&e.stencilManager.popStencil(t,t._webGL[i.id].data[0],e)},k.WebGLMaskManager.prototype.destroy=function(){this.gl=null},k.WebGLStencilManager=function(){this.stencilStack=[],this.reverse=!0,this.count=0},k.WebGLStencilManager.prototype.setContext=function(t){this.gl=t},k.WebGLStencilManager.prototype.pushStencil=function(t,e,i){var s=this.gl;this.bindGraphics(t,e,i),0===this.stencilStack.length&&(s.enable(s.STENCIL_TEST),s.clear(s.STENCIL_BUFFER_BIT),this.reverse=!0,this.count=0),this.stencilStack.push(e);var n=this.count;s.colorMask(!1,!1,!1,!1),s.stencilFunc(s.ALWAYS,0,255),s.stencilOp(s.KEEP,s.KEEP,s.INVERT),1===e.mode?(s.drawElements(s.TRIANGLE_FAN,e.indices.length-4,s.UNSIGNED_SHORT,0),this.reverse?(s.stencilFunc(s.EQUAL,255-n,255),s.stencilOp(s.KEEP,s.KEEP,s.DECR)):(s.stencilFunc(s.EQUAL,n,255),s.stencilOp(s.KEEP,s.KEEP,s.INCR)),s.drawElements(s.TRIANGLE_FAN,4,s.UNSIGNED_SHORT,2*(e.indices.length-4)),this.reverse?s.stencilFunc(s.EQUAL,255-(n+1),255):s.stencilFunc(s.EQUAL,n+1,255),this.reverse=!this.reverse):(this.reverse?(s.stencilFunc(s.EQUAL,n,255),s.stencilOp(s.KEEP,s.KEEP,s.INCR)):(s.stencilFunc(s.EQUAL,255-n,255),s.stencilOp(s.KEEP,s.KEEP,s.DECR)),s.drawElements(s.TRIANGLE_STRIP,e.indices.length,s.UNSIGNED_SHORT,0),this.reverse?s.stencilFunc(s.EQUAL,n+1,255):s.stencilFunc(s.EQUAL,255-(n+1),255)),s.colorMask(!0,!0,!0,!0),s.stencilOp(s.KEEP,s.KEEP,s.KEEP),this.count++},k.WebGLStencilManager.prototype.bindGraphics=function(t,e,i){this._currentGraphics=t;var s,n=this.gl,r=i.projection,o=i.offset;1===e.mode?(s=i.shaderManager.complexPrimitiveShader,i.shaderManager.setShader(s),n.uniform1f(s.flipY,i.flipY),n.uniformMatrix3fv(s.translationMatrix,!1,t.worldTransform.toArray(!0)),n.uniform2f(s.projectionVector,r.x,-r.y),n.uniform2f(s.offsetVector,-o.x,-o.y),n.uniform3fv(s.tintColor,Phaser.Color.hexToRGBArray(t.tint)),n.uniform3fv(s.color,e.color),n.uniform1f(s.alpha,t.worldAlpha*e.alpha),n.bindBuffer(n.ARRAY_BUFFER,e.buffer),n.vertexAttribPointer(s.aVertexPosition,2,n.FLOAT,!1,8,0)):(s=i.shaderManager.primitiveShader,i.shaderManager.setShader(s),n.uniformMatrix3fv(s.translationMatrix,!1,t.worldTransform.toArray(!0)),n.uniform1f(s.flipY,i.flipY),n.uniform2f(s.projectionVector,r.x,-r.y),n.uniform2f(s.offsetVector,-o.x,-o.y),n.uniform3fv(s.tintColor,Phaser.Color.hexToRGBArray(t.tint)),n.uniform1f(s.alpha,t.worldAlpha),n.bindBuffer(n.ARRAY_BUFFER,e.buffer),n.vertexAttribPointer(s.aVertexPosition,2,n.FLOAT,!1,24,0),n.vertexAttribPointer(s.colorAttribute,4,n.FLOAT,!1,24,8)),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,e.indexBuffer)},k.WebGLStencilManager.prototype.popStencil=function(t,e,i){var s=this.gl;if(this.stencilStack.pop(),this.count--,0===this.stencilStack.length)s.disable(s.STENCIL_TEST);else{var n=this.count;this.bindGraphics(t,e,i),s.colorMask(!1,!1,!1,!1),1===e.mode?(this.reverse=!this.reverse,this.reverse?(s.stencilFunc(s.EQUAL,255-(n+1),255),s.stencilOp(s.KEEP,s.KEEP,s.INCR)):(s.stencilFunc(s.EQUAL,n+1,255),s.stencilOp(s.KEEP,s.KEEP,s.DECR)),s.drawElements(s.TRIANGLE_FAN,4,s.UNSIGNED_SHORT,2*(e.indices.length-4)),s.stencilFunc(s.ALWAYS,0,255),s.stencilOp(s.KEEP,s.KEEP,s.INVERT),s.drawElements(s.TRIANGLE_FAN,e.indices.length-4,s.UNSIGNED_SHORT,0)):(this.reverse?(s.stencilFunc(s.EQUAL,n+1,255),s.stencilOp(s.KEEP,s.KEEP,s.DECR)):(s.stencilFunc(s.EQUAL,255-(n+1),255),s.stencilOp(s.KEEP,s.KEEP,s.INCR)),s.drawElements(s.TRIANGLE_STRIP,e.indices.length,s.UNSIGNED_SHORT,0)),this.reverse?s.stencilFunc(s.EQUAL,n,255):s.stencilFunc(s.EQUAL,255-n,255),s.colorMask(!0,!0,!0,!0),s.stencilOp(s.KEEP,s.KEEP,s.KEEP)}},k.WebGLStencilManager.prototype.destroy=function(){this.stencilStack=null,this.gl=null},k.WebGLShaderManager=function(){this.maxAttibs=10,this.attribState=[],this.tempAttribState=[];for(var t=0;t<this.maxAttibs;t++)this.attribState[t]=!1;this.stack=[]},k.WebGLShaderManager.prototype.constructor=k.WebGLShaderManager,k.WebGLShaderManager.prototype.setContext=function(t){this.gl=t,this.primitiveShader=new k.PrimitiveShader(t),this.complexPrimitiveShader=new k.ComplexPrimitiveShader(t),this.defaultShader=new k.PixiShader(t),this.fastShader=new k.PixiFastShader(t),this.stripShader=new k.StripShader(t),this.creatureShader=k.CreatureShader?new k.CreatureShader(t):null,this.setShader(this.defaultShader)},k.WebGLShaderManager.prototype.setAttribs=function(t){var e;for(e=0;e<this.tempAttribState.length;e++)this.tempAttribState[e]=!1;for(e=0;e<t.length;e++){var i=t[e];this.tempAttribState[i]=!0}var s=this.gl;for(e=0;e<this.attribState.length;e++)this.attribState[e]!==this.tempAttribState[e]&&(this.attribState[e]=this.tempAttribState[e],this.tempAttribState[e]?s.enableVertexAttribArray(e):s.disableVertexAttribArray(e))},k.WebGLShaderManager.prototype.setShader=function(t){return this._currentId!==t._UID&&(this._currentId=t._UID,this.currentShader=t,this.gl.useProgram(t.program),this.setAttribs(t.attributes),!0)},k.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},k.WebGLSpriteBatch=function(t){this.game=t,this.vertSize=5,this.size=2e3,this.vertexSize=24;var e=this.vertexSize*this.size*4,i=6*this.size;this.vertices=new ArrayBuffer(e),this.positions=new Float32Array(this.vertices),this.colors=new Uint32Array(this.vertices),this.indices=new Uint16Array(i);for(var s=this.lastIndexCount=0,n=0;s<i;s+=6,n+=4)this.indices[s+0]=n+0,this.indices[s+1]=n+1,this.indices[s+2]=n+2,this.indices[s+3]=n+0,this.indices[s+4]=n+2,this.indices[s+5]=n+3;this.drawing=!1,this.currentBatchSize=0,this.currentBaseTexture=null,this.dirty=!0,this.textures=[],this.blendMod