mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 05:33:35 +00:00
6 lines
85 KiB
JavaScript
6 lines
85 KiB
JavaScript
|
/* Phaser v2.6.2 PIXI Build - http://phaser.io - @photonstorm - (c) 2016 Photon Storm Ltd. */
|
||
|
|
||
|
(function(){var a=this,b=b||{};return b.game=null,b.WEBGL_RENDERER=0,b.CANVAS_RENDERER=1,b.VERSION="v2.2.9",b._UID=0,"undefined"!=typeof Float32Array?(b.Float32Array=Float32Array,b.Uint16Array=Uint16Array,b.Uint32Array=Uint32Array,b.ArrayBuffer=ArrayBuffer):(b.Float32Array=Array,b.Uint16Array=Array),b.PI_2=2*Math.PI,b.RAD_TO_DEG=180/Math.PI,b.DEG_TO_RAD=Math.PI/180,b.RETINA_PREFIX="@2x",b.DisplayObject=function(){this.position=new b.Point(0,0),this.scale=new b.Point(1,1),this.pivot=new b.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 b.Matrix,this.worldPosition=new b.Point(0,0),this.worldScale=new b.Point(1,1),this.worldRotation=0,this.filterArea=null,this._sr=0,this._cr=1,this._bounds=new b.Rectangle(0,0,0,0),this._currentBounds=null,this._mask=null,this._cacheAsBitmap=!1,this._cacheIsDirty=!1},b.DisplayObject.prototype.constructor=b.DisplayObject,b.DisplayObject.prototype={destroy:function(){if(this.children){for(var a=this.children.length;a--;)this.children[a].destroy();this.children=[]}this.hitArea=null,this.parent=null,this.worldTransform=null,this.filterArea=null,this.renderable=!1,this._bounds=null,this._currentBounds=null,this._mask=null,this._destroyCachedSprite()},updateTransform:function(a){if(!a&&!this.parent&&!this.game)return this;var c=this.parent;a?c=a:this.parent||(c=this.game.world);var d,e,f,g,h,i,j=c.worldTransform,k=this.worldTransform;return this.rotation%b.PI_2?(this.rotation!==this.rotationCache&&(this.rotationCache=this.rotation,this._sr=Math.sin(this.rotation),this._cr=Math.cos(this.rotation)),d=this._cr*this.scale.x,e=this._sr*this.scale.x,f=-this._sr*this.scale.y,g=this._cr*this.scale.y,h=this.position.x,i=this.position.y,(this.pivot.x||this.pivot.y)&&(h-=this.pivot.x*d+this.pivot.y*f,i-=this.pivot.x*e+this.pivot.y*g),k.a=d*j.a+e*j.c,k.b=d*j.b+e*j.d,k.c=f*j.a+g*j.c,k.d=f*j.b+g*j.d,k.tx=h*j.a+i*j.c+j.tx,k.ty=h*j.b+i*j.d+j.ty):(d=this.scale.x,g=this.scale.y,h=this.position.x-this.pivot.x*d,i=this.position.y-this.pivot.y*g,k.a=d*j.a,k.b=d*j.b,k.c=g*j.c,k.d=g*j.d,k.tx=h*j.a+i*j.c+j.tx,k.ty=h*j.b+i*j.d+j.ty),this.worldAlpha=this.alpha*c.worldAlpha,this.worldPosition.set(k.tx,k.ty),this.worldScale.set(this.scale.x*Math.sqrt(k.a*k.a+k.c*k.c),this.scale.y*Math.sqrt(k.b*k.b+k.d*k.d)),this.worldRotation=Math.atan2(-k.c,k.d),this._currentBounds=null,this.transformCallback&&this.transformCallback.call(this.transformCallbackContext,k,j),this},preUpdate:function(){},generateTexture:function(a,c,d){var e=this.getLocalBounds(),f=new b.RenderTexture(0|e.width,0|e.height,d,c,a);return b.DisplayObject._tempMatrix.tx=-e.x,b.DisplayObject._tempMatrix.ty=-e.y,f.render(this,b.DisplayObject._tempMatrix),f},updateCache:function(){return this._generateCachedSprite(),this},toGlobal:function(a){return this.updateTransform(),this.worldTransform.apply(a)},toLocal:function(a,b){return b&&(a=b.toGlobal(a)),this.updateTransform(),this.worldTransform.applyInverse(a)},_renderCachedSprite:function(a){this._cachedSprite.worldAlpha=this.worldAlpha,a.gl?b.Sprite.prototype._renderWebGL.call(this._cachedSprite,a):b.Sprite.prototype._renderCanvas.call(this._cachedSprite,a)},_generateCachedSprite:function(){this._cacheAsBitmap=!1;var a=this.getLocalBounds();if(a.width=Math.max(1,Math.ceil(a.width)),a.height=Math.max(1,Math.ceil(a.height)),this.updateTransform(),this._cachedSprite)this._cachedSprite.texture.resize(a.width,a.height);else{var c=new b.RenderTexture(a.width,a.height);this._cachedSprite=new b.Sprite(c),this._cachedSprite.worldTransform=this.worldTransform}var d=this._filters;this._filters=null,this._cachedSprite.filters=d,b.DisplayObject._tempMatrix.tx=-a.x,b.DisplayObject._tempMatrix.ty=-a.y,this._cachedSprite.texture.render(this,b.DisplayObject._tempMatrix,!0),this._cachedSprite.anchor.x=-(a.x/a.width),this._cachedSprite.anchor.y=-(a.y/a.height),this._filters=d,this._cacheAsBitmap=!0},_destroyCachedSprite:function(){this._cachedSprite&&(this._cachedSprite.texture.destroy(!0),this._cachedSprite=null)}},b.DisplayObject.p
|
||
|
this.renderSession.resolution=this.resolution,this.initContext(),this.mapBlendModes()},b.WebGLRenderer.prototype.constructor=b.WebGLRenderer,b.WebGLRenderer.prototype.initContext=function(){var a=this.view.getContext("webgl",this._contextOptions)||this.view.getContext("experimental-webgl",this._contextOptions);if(this.gl=a,!a)throw new Error("This browser does not support webGL. Try using the canvas renderer");this.glContextId=a.id=b.WebGLRenderer.glContextId++,b.glContexts[this.glContextId]=a,b.instances[this.glContextId]=this,a.disable(a.DEPTH_TEST),a.disable(a.CULL_FACE),a.enable(a.BLEND),this.shaderManager.setContext(a),this.spriteBatch.setContext(a),this.maskManager.setContext(a),this.filterManager.setContext(a),this.blendModeManager.setContext(a),this.stencilManager.setContext(a),this.renderSession.gl=this.gl,this.resize(this.width,this.height)},b.WebGLRenderer.prototype.render=function(a){if(!this.contextLost){var b=this.gl;b.viewport(0,0,this.width,this.height),b.bindFramebuffer(b.FRAMEBUFFER,null),this.game.clearBeforeRender&&(b.clearColor(a._bgColor.r,a._bgColor.g,a._bgColor.b,a._bgColor.a),b.clear(b.COLOR_BUFFER_BIT)),this.offset.x=this.game.camera._shake.x,this.offset.y=this.game.camera._shake.y,this.renderDisplayObject(a,this.projection)}},b.WebGLRenderer.prototype.renderDisplayObject=function(a,c,d,e){this.renderSession.blendModeManager.setBlendMode(b.blendModes.NORMAL),this.renderSession.drawCount=0,this.renderSession.flipY=d?-1:1,this.renderSession.projection=c,this.renderSession.offset=this.offset,this.spriteBatch.begin(this.renderSession),this.filterManager.begin(this.renderSession,d),a._renderWebGL(this.renderSession,e),this.spriteBatch.end()},b.WebGLRenderer.prototype.resize=function(a,b){this.width=a*this.resolution,this.height=b*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},b.WebGLRenderer.prototype.updateTexture=function(a){if(!a.hasLoaded)return!1;var c=this.gl;return a._glTextures[c.id]||(a._glTextures[c.id]=c.createTexture()),c.bindTexture(c.TEXTURE_2D,a._glTextures[c.id]),c.pixelStorei(c.UNPACK_PREMULTIPLY_ALPHA_WEBGL,a.premultipliedAlpha),c.texImage2D(c.TEXTURE_2D,0,c.RGBA,c.RGBA,c.UNSIGNED_BYTE,a.source),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MAG_FILTER,a.scaleMode===b.scaleModes.LINEAR?c.LINEAR:c.NEAREST),a.mipmap&&b.isPowerOfTwo(a.width,a.height)?(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,a.scaleMode===b.scaleModes.LINEAR?c.LINEAR_MIPMAP_LINEAR:c.NEAREST_MIPMAP_NEAREST),c.generateMipmap(c.TEXTURE_2D)):c.texParameteri(c.TEXTURE_2D,c.TEXTURE_MIN_FILTER,a.scaleMode===b.scaleModes.LINEAR?c.LINEAR:c.NEAREST),a._powerOf2?(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.REPEAT),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.REPEAT)):(c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_S,c.CLAMP_TO_EDGE),c.texParameteri(c.TEXTURE_2D,c.TEXTURE_WRAP_T,c.CLAMP_TO_EDGE)),a._dirty[c.id]=!1,!0},b.WebGLRenderer.prototype.destroy=function(){b.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,b.CanvasPool.remove(this),b.instances[this.glContextId]=null,b.WebGLRenderer.glContextId--},b.WebGLRenderer.prototype.mapBlendModes=function(){var a=this.gl;if(!b.blendModesWebGL){var c=[],d=b.blendModes;c[d.NORMAL]=[a.ONE,a.ONE_MINUS_SRC_ALPHA],c[d.ADD]=[a.SRC_ALPHA,a.DST_ALPHA],c[d.MULTIPLY]=[a.DST_COLOR,a.ONE_MINUS_SRC_ALPHA],c[d.SCREEN]=[a.SRC_ALPHA,a.ONE],c[d.OVERLAY]=[a.ONE,a.ONE_MINUS_SRC_ALPHA],c[d.DARKEN]=[a.ONE,a.ONE_MINUS_SRC_ALPHA],c[d.LIGHTEN]=[a.ONE,a.ONE_MINUS_SRC_ALPHA],c[d.COLOR_DODGE]=[a.ONE,a.ONE_MINUS_SRC_ALPHA],c[d.COLOR_BURN]=[a.ONE,a.ONE_MINUS_S
|
||
|
var d=a.context.getImageData(1,0,1,1);return d.data[0]===c.data[0]&&d.data[1]===c.data[1]&&d.data[2]===c.data[2]&&d.data[3]===c.data[3]},b.CanvasTinter.canHandleAlpha=b.CanvasTinter.checkInverseAlpha(),b.CanvasTinter.canUseMultiply=b.canUseNewCanvasBlendModes(),b.CanvasTinter.tintMethod=b.CanvasTinter.canUseMultiply?b.CanvasTinter.tintWithMultiply:b.CanvasTinter.tintWithPerPixel,b.CanvasRenderer=function(a){this.game=a,b.defaultRenderer||(b.defaultRenderer=this),this.type=b.CANVAS_RENDERER,this.resolution=a.resolution,this.clearBeforeRender=a.clearBeforeRender,this.transparent=a.transparent,this.autoResize=!1,this.width=a.width*this.resolution,this.height=a.height*this.resolution,this.view=a.canvas,this.context=this.view.getContext("2d",{alpha:this.transparent}),this.refresh=!0,this.count=0,this.maskManager=new b.CanvasMaskManager,this.renderSession={context:this.context,maskManager:this.maskManager,scaleMode:null,smoothProperty:Phaser.Canvas.getSmoothingPrefix(this.context),roundPixels:!1},this.mapBlendModes(),this.resize(this.width,this.height)},b.CanvasRenderer.prototype.constructor=b.CanvasRenderer,b.CanvasRenderer.prototype.render=function(a){this.context.setTransform(1,0,0,1,0,0),this.context.globalAlpha=1,this.renderSession.currentBlendMode=0,this.renderSession.shakeX=this.game.camera._shake.x,this.renderSession.shakeY=this.game.camera._shake.y,this.context.globalCompositeOperation="source-over",navigator.isCocoonJS&&this.view.screencanvas&&(this.context.fillStyle="black",this.context.clear()),this.clearBeforeRender&&(this.transparent?this.context.clearRect(0,0,this.width,this.height):a._bgColor&&(this.context.fillStyle=a._bgColor.rgba,this.context.fillRect(0,0,this.width,this.height))),this.renderDisplayObject(a)},b.CanvasRenderer.prototype.destroy=function(a){void 0===a&&(a=!0),a&&this.view.parent&&this.view.parent.removeChild(this.view),this.view=null,this.context=null,this.maskManager=null,this.renderSession=null},b.CanvasRenderer.prototype.resize=function(a,c){this.width=a*this.resolution,this.height=c*this.resolution,this.view.width=this.width,this.view.height=this.height,this.autoResize&&(this.view.style.width=this.width/this.resolution+"px",this.view.style.height=this.height/this.resolution+"px"),this.renderSession.smoothProperty&&(this.context[this.renderSession.smoothProperty]=this.renderSession.scaleMode===b.scaleModes.LINEAR)},b.CanvasRenderer.prototype.renderDisplayObject=function(a,b,c){this.renderSession.context=b||this.context,this.renderSession.resolution=this.resolution,a._renderCanvas(this.renderSession,c)},b.CanvasRenderer.prototype.mapBlendModes=function(){if(!b.blendModesCanvas){var a=[],c=b.blendModes,d=b.canUseNewCanvasBlendModes();a[c.NORMAL]="source-over",a[c.ADD]="lighter",a[c.MULTIPLY]=d?"multiply":"source-over",a[c.SCREEN]=d?"screen":"source-over",a[c.OVERLAY]=d?"overlay":"source-over",a[c.DARKEN]=d?"darken":"source-over",a[c.LIGHTEN]=d?"lighten":"source-over",a[c.COLOR_DODGE]=d?"color-dodge":"source-over",a[c.COLOR_BURN]=d?"color-burn":"source-over",a[c.HARD_LIGHT]=d?"hard-light":"source-over",a[c.SOFT_LIGHT]=d?"soft-light":"source-over",a[c.DIFFERENCE]=d?"difference":"source-over",a[c.EXCLUSION]=d?"exclusion":"source-over",a[c.HUE]=d?"hue":"source-over",a[c.SATURATION]=d?"saturation":"source-over",a[c.COLOR]=d?"color":"source-over",a[c.LUMINOSITY]=d?"luminosity":"source-over",b.blendModesCanvas=a}},b.BaseTexture=function(a,c){this.resolution=1,this.width=100,this.height=100,this.scaleMode=c||b.scaleModes.DEFAULT,this.hasLoaded=!1,this.source=a,this.premultipliedAlpha=!0,this._glTextures=[],this.mipmap=!1,this._dirty=[!0,!0,!0,!0],a&&((this.source.complete||this.source.getContext)&&this.source.width&&this.source.height&&(this.hasLoaded=!0,this.width=this.source.naturalWidth||this.source.width,this.height=this.source.naturalHeight||this.source.height,this.dirty()),this.skipRender=!1,this._powerOf2=!1)},b.BaseTexture.prototype.constructor=b.BaseTexture,b.BaseTexture.prototype.forceLoaded=function(a,b){this.hasLoaded=!0,this.width=a,this.height=b,this.dirty()},b.BaseTexture.prototype.de
|
||
|
//# sourceMappingURL=pixi.map
|