diff --git a/README.md b/README.md index 17706a331..2e27f66b9 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,7 @@ Version 2.2.0 - "Bethal" - in development ### New Features +* Updated to Pixi v2.1.0 - see seprate change log entry below. * Cache.getRenderTexture will retrieve a RenderTexture that is stored in the Phaser Cache. This method replaces Cache.getTexture which is now deprecated. * Cache.autoResolveURL is a new boolean (default `false`) that automatically builds a cached map of all loaded assets vs. their absolute URLs, for use with Cache.getURL and Cache.checkURL. Note that in 2.1.3 and earlier this was enabled by default, but has since been moved behind this property which needs to be set to `true` *before* you load any assets to enable. * You can now call Tween.to again on a Tween that has already completed. This will re-use the same tween, on the original object, without having to recreate the Tween again. This allows a single tween instance to be re-used multiple times, providing they are linked to the same object (thanks InsaneHero) @@ -142,7 +143,6 @@ Version 2.2.0 - "Bethal" - in development * ArcadePhysics.skipQuadTree is now set to `true` by default. A QuadTree is a wonderful thing if the objects in your game are well spaced out. But in tightly packed games, especially those with tilemaps or single-screen games, they are a considerable performance drain and eat up CPU. We've taken the decision to disable the Arcade Physics QuadTree by default. It's all still in there and can be re-enabled via `game.physics.arcade.skipQuadTree = false`, but please only do so if you're sure your game benefits from this. * Phaser.DOM now houses new DOM functions. Some have been moved over from ScaleManager as appropriate. - ### Bug Fixes * Tilemaps in WebGL wouldn't update after the first frame due to a subtle change in how Pixi uploads new textures to the GPU. @@ -161,6 +161,31 @@ Version 2.2.0 - "Bethal" - in development * Lots of the Cache getters (such as `Cache.getbitmapData`) would return `undefined` if the asset couldn't be found. They now all consistently return `null` for missing entries (thanks @Matoking #1305) * Phaser games should now work again from the CocoonJS Launcher. +### Pixi 2.1.0 New Features + +* unloadFromGPU added to PIXI.BaseTexture +* PIXI.VideoTexture added +* PIXI.RoundedRectangle added +* Ensured all float32arrays use PIXI.Float32Array +* Removed the use of call in updateTransform (as its 10x faster to run the function directly) +* autoResize option added to renderer options (default is false). Pixi no longer automatically changes the style of the canvas. +* PIXI.RenderTexture.getCanvas optimized + +### Pixi 2.1.0 Bug Fixes + +* Fix destroy method of PIXI.WebGLRenderer +* Fixed Graphics.drawRoundedRectangle +* Fixed Graphics.arcTo issue +* Fixed Graphics.arc issue +* Fixed Graphics.cacheAsBitmap alpha issue +* Fixed PIXI.Strip alpha issue +* Fixed PIXI.DisplayObject.cacheAsBitmap alpha issue +* Fixed PIXI.RenderTexture Canvas Clear bug +* Fixed PIXI.DisplayObject.updateTransform issue +* Fixed webGL Shader textures issue +* Fixed PIXI.DisplayObject.getLocalPosition() +* Fixed CocoonJS crashing, when loading destroyed texture +* Fix eventTarget emit bug For details about changes made in previous versions of Phaser see the full Change Log at https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md diff --git a/build/config.php b/build/config.php index c9542abf4..bf2d533d3 100644 --- a/build/config.php +++ b/build/config.php @@ -39,6 +39,7 @@ + diff --git a/src/Phaser.js b/src/Phaser.js index 7fea7c7a6..13e2f9810 100644 --- a/src/Phaser.js +++ b/src/Phaser.js @@ -10,7 +10,7 @@ */ var Phaser = Phaser || { - VERSION: '2.2.0-RC3', + VERSION: '2.2.0-RC4', GAMES: [], AUTO: 0, diff --git a/src/input/Input.js b/src/input/Input.js index b10d186d2..c34ed778a 100644 --- a/src/input/Input.js +++ b/src/input/Input.js @@ -776,6 +776,7 @@ Phaser.Input.prototype = { for (var i = 0; i < this.pointers.length; i++) { var pointer = this.pointers[i]; + if (pointer.pointerId === pointerId) { return pointer; diff --git a/src/pixi/InteractionData.js b/src/pixi/InteractionData.js index fa84a6d47..b0d8a6a90 100644 --- a/src/pixi/InteractionData.js +++ b/src/pixi/InteractionData.js @@ -49,8 +49,8 @@ PIXI.InteractionData.prototype.getLocalPosition = function(displayObject, point) var global = this.global; // do a cheeky transform to get the mouse coords; - var a00 = worldTransform.a, a01 = worldTransform.b, a02 = worldTransform.tx, - a10 = worldTransform.c, a11 = worldTransform.d, a12 = worldTransform.ty, + var a00 = worldTransform.a, a01 = worldTransform.c, a02 = worldTransform.tx, + a10 = worldTransform.b, a11 = worldTransform.d, a12 = worldTransform.ty, id = 1 / (a00 * a11 + a01 * -a10); point = point || new PIXI.Point(); diff --git a/src/pixi/Pixi.js b/src/pixi/Pixi.js index 1eb101017..2672346c8 100644 --- a/src/pixi/Pixi.js +++ b/src/pixi/Pixi.js @@ -16,7 +16,7 @@ PIXI.WEBGL_RENDERER = 0; PIXI.CANVAS_RENDERER = 1; // useful for testing against if your lib is using pixi. -PIXI.VERSION = "v2.0.0"; +PIXI.VERSION = "v2.1.0"; // the various blend modes supported by pixi @@ -81,7 +81,8 @@ PIXI.defaultRenderOptions = { antialias:false, preserveDrawingBuffer:false, resolution:1, - clearBeforeRender:true + clearBeforeRender:true, + autoResize:false } PIXI.sayHello = function (type) diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js index f7f877b6e..229594940 100644 --- a/src/pixi/display/DisplayObject.js +++ b/src/pixi/display/DisplayObject.js @@ -518,13 +518,14 @@ PIXI.DisplayObject.prototype.updateTransform = function() // lets do the fast version as we know there is no rotation.. a = this.scale.x; d = this.scale.y; - tx = this.position.x - this.pivot.x * a; - ty = this.position.y - this.pivot.y * d; - wt.a = pt.a * a; - wt.b = pt.b * d; - wt.c = pt.c * a; - wt.d = pt.d * d; + tx = this.position.x; + ty = this.position.y; + + wt.a = a * pt.a; + wt.b = a * pt.b; + wt.c = d * pt.c; + wt.d = d * pt.d; wt.tx = tx * pt.a + ty * pt.c + pt.tx; wt.ty = tx * pt.b + ty * pt.d + pt.ty; } @@ -540,6 +541,9 @@ PIXI.DisplayObject.prototype.updateTransform = function() }; +// performance increase to avoid using call.. (10x faster) +PIXI.DisplayObject.prototype.displayObjectUpdateTransform = PIXI.DisplayObject.prototype.updateTransform; + /** * Retrieves the bounds of the displayObject as a rectangle object * diff --git a/src/pixi/display/DisplayObjectContainer.js b/src/pixi/display/DisplayObjectContainer.js index bc4fd6903..d6293efce 100644 --- a/src/pixi/display/DisplayObjectContainer.js +++ b/src/pixi/display/DisplayObjectContainer.js @@ -22,12 +22,16 @@ PIXI.DisplayObjectContainer = function() * @readOnly */ this.children = []; + + // fast access to update transform.. + }; // constructor PIXI.DisplayObjectContainer.prototype = Object.create( PIXI.DisplayObject.prototype ); PIXI.DisplayObjectContainer.prototype.constructor = PIXI.DisplayObjectContainer; + /** * The width of the displayObjectContainer, setting this will actually modify the scale to achieve the value set * @@ -280,7 +284,9 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function() { if(!this.visible)return; - PIXI.DisplayObject.prototype.updateTransform.call( this ); + this.displayObjectUpdateTransform(); + + //PIXI.DisplayObject.prototype.updateTransform.call( this ); if(this._cacheAsBitmap)return; @@ -290,6 +296,9 @@ PIXI.DisplayObjectContainer.prototype.updateTransform = function() } }; +// performance increase to avoid using call.. (10x faster) +PIXI.DisplayObjectContainer.prototype.displayObjectContainerUpdateTransform = PIXI.DisplayObjectContainer.prototype.updateTransform; + /** * Retrieves the bounds of the displayObjectContainer as a rectangle. The bounds calculation takes all visible children into consideration. * diff --git a/src/pixi/geom/RoundedRectangle.js b/src/pixi/geom/RoundedRectangle.js new file mode 100644 index 000000000..9ad317573 --- /dev/null +++ b/src/pixi/geom/RoundedRectangle.js @@ -0,0 +1,94 @@ +/** + * @author Mat Groves http://matgroves.com/ + */ + +/** + * the Rounded Rectangle object is an area defined by its position and has nice rounded corners, as indicated by its top-left corner point (x, y) and by its width and its height. + * + * @class Rounded Rectangle + * @constructor + * @param x {Number} The X coordinate of the upper-left corner of the rounded rectangle + * @param y {Number} The Y coordinate of the upper-left corner of the rounded rectangle + * @param width {Number} The overall width of this rounded rectangle + * @param height {Number} The overall height of this rounded rectangle + * @param radius {Number} The overall radius of this corners of this rounded rectangle + */ +PIXI.RoundedRectangle = function(x, y, width, height, radius) +{ + /** + * @property x + * @type Number + * @default 0 + */ + this.x = x || 0; + + /** + * @property y + * @type Number + * @default 0 + */ + this.y = y || 0; + + /** + * @property width + * @type Number + * @default 0 + */ + this.width = width || 0; + + /** + * @property height + * @type Number + * @default 0 + */ + this.height = height || 0; + + /** + * @property radius + * @type Number + * @default 20 + */ + this.radius = radius || 20; +}; + +/** + * Creates a clone of this Rounded Rectangle + * + * @method clone + * @return {rounded Rectangle} a copy of the rounded rectangle + */ +PIXI.RoundedRectangle.prototype.clone = function() +{ + return new PIXI.RoundedRectangle(this.x, this.y, this.width, this.height, this.radius); +}; + +/** + * Checks whether the x and y coordinates given are contained within this Rounded Rectangle + * + * @method contains + * @param x {Number} The X coordinate of the point to test + * @param y {Number} The Y coordinate of the point to test + * @return {Boolean} Whether the x/y coordinates are within this Rounded Rectangle + */ +PIXI.RoundedRectangle.prototype.contains = function(x, y) +{ + if(this.width <= 0 || this.height <= 0) + return false; + + var x1 = this.x; + if(x >= x1 && x <= x1 + this.width) + { + var y1 = this.y; + + if(y >= y1 && y <= y1 + this.height) + { + return true; + } + } + + return false; +}; + +// constructor +PIXI.RoundedRectangle.prototype.constructor = PIXI.RoundedRectangle; + diff --git a/src/pixi/primitives/Graphics.js b/src/pixi/primitives/Graphics.js index 6dbf64478..b99a4cfd5 100644 --- a/src/pixi/primitives/Graphics.js +++ b/src/pixi/primitives/Graphics.js @@ -101,6 +101,8 @@ PIXI.Graphics = function() */ this.boundsPadding = 0; + this._localBounds = new PIXI.Rectangle(0,0,1,1); + /** * Used to detect if the graphics object has changed. If this is set to true then the graphics object will be recalculated. * @@ -355,17 +357,17 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius) { if( this.currentPath ) { - if(this.currentPath.shape.points.length === 0)this.currentPath.shape.points = [x1, y1]; + if(this.currentPath.shape.points.length === 0) + { + this.currentPath.shape.points.push(x1, y1); + } } else { this.moveTo(x1, y1); } - // check that path contains subpaths - if( this.currentPath.length === 0)this.moveTo(x1, y1); - - var points = this.currentPath; + var points = this.currentPath.shape.points; var fromX = points[points.length-2]; var fromY = points[points.length-1]; var a1 = fromY - y1; @@ -374,9 +376,14 @@ PIXI.Graphics.prototype.arcTo = function(x1, y1, x2, y2, radius) var b2 = x2 - x1; var mm = Math.abs(a1 * b2 - b1 * a2); + if (mm < 1.0e-8 || radius === 0) { - points.push(x1, y1); + if( points[points.length-2] !== x1 || points[points.length-1] !== y1) + { + //console.log(">>") + points.push(x1, y1); + } } else { @@ -420,15 +427,19 @@ PIXI.Graphics.prototype.arc = function(cx, cy, radius, startAngle, endAngle, ant { var startX = cx + Math.cos(startAngle) * radius; var startY = cy + Math.sin(startAngle) * radius; - + var points = this.currentPath.shape.points; - if(points.length !== 0 && points[points.length-2] !== startX || points[points.length-1] !== startY) + if(points.length === 0) { this.moveTo(startX, startY); points = this.currentPath.shape.points; } - + else if( points[points.length-2] !== startX || points[points.length-1] !== startY) + { + points.push(startX, startY); + } + if (startAngle === endAngle)return this; if( !anticlockwise && endAngle <= startAngle ) @@ -543,7 +554,7 @@ PIXI.Graphics.prototype.drawRect = function( x, y, width, height ) */ PIXI.Graphics.prototype.drawRoundedRect = function( x, y, width, height, radius ) { - this.drawShape({ points:[x, y, width, height, radius], type:PIXI.Graphics.RREC }); + this.drawShape(new PIXI.RoundedRectangle(x, y, width, height, radius)); return this; }; @@ -804,13 +815,13 @@ PIXI.Graphics.prototype.getBounds = function( matrix ) if(this.dirty) { - this.updateBounds(); + this.updateLocalBounds(); this.webGLDirty = true; this.cachedSpriteDirty = true; this.dirty = false; } - var bounds = this._bounds; + var bounds = this._localBounds; var w0 = bounds.x; var w1 = bounds.width + bounds.x; @@ -861,21 +872,21 @@ PIXI.Graphics.prototype.getBounds = function( matrix ) maxY = y3 > maxY ? y3 : maxY; maxY = y4 > maxY ? y4 : maxY; - bounds.x = minX; - bounds.width = maxX - minX; + this._bounds.x = minX; + this._bounds.width = maxX - minX; - bounds.y = minY; - bounds.height = maxY - minY; + this._bounds.y = minY; + this._bounds.height = maxY - minY; - return bounds; + return this._bounds; }; /** * Update the bounds of the object * - * @method updateBounds + * @method updateLocalBounds */ -PIXI.Graphics.prototype.updateBounds = function() +PIXI.Graphics.prototype.updateLocalBounds = function() { var minX = Infinity; var maxX = -Infinity; @@ -961,13 +972,12 @@ PIXI.Graphics.prototype.updateBounds = function() } var padding = this.boundsPadding; - var bounds = this._bounds; - bounds.x = minX - padding; - bounds.width = (maxX - minX) + padding * 2; + this._localBounds.x = minX - padding; + this._localBounds.width = (maxX - minX) + padding * 2; - bounds.y = minY - padding; - bounds.height = (maxY - minY) + padding * 2; + this._localBounds.y = minY - padding; + this._localBounds.height = (maxY - minY) + padding * 2; }; /** @@ -1111,3 +1121,5 @@ PIXI.Polygon.prototype.type = PIXI.Graphics.POLY; PIXI.Rectangle.prototype.type = PIXI.Graphics.RECT; PIXI.Circle.prototype.type = PIXI.Graphics.CIRC; PIXI.Ellipse.prototype.type = PIXI.Graphics.ELIP; +PIXI.RoundedRectangle.prototype.type = PIXI.Graphics.RREC; + diff --git a/src/pixi/renderers/canvas/CanvasGraphics.js b/src/pixi/renderers/canvas/CanvasGraphics.js index ec63e5592..632e23f35 100644 --- a/src/pixi/renderers/canvas/CanvasGraphics.js +++ b/src/pixi/renderers/canvas/CanvasGraphics.js @@ -148,12 +148,11 @@ PIXI.CanvasGraphics.renderGraphics = function(graphics, context) } else if (data.type === PIXI.Graphics.RREC) { - var pts = shape.points; - var rx = pts[0]; - var ry = pts[1]; - var width = pts[2]; - var height = pts[3]; - var radius = pts[4]; + var rx = shape.x; + var ry = shape.y; + var width = shape.width; + var height = shape.height; + var radius = shape.radius; var maxRadius = Math.min(width, height) / 2 | 0; radius = radius > maxRadius ? maxRadius : radius; diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js index a9148f57a..291c68013 100644 --- a/src/pixi/renderers/webgl/WebGLRenderer.js +++ b/src/pixi/renderers/webgl/WebGLRenderer.js @@ -3,6 +3,7 @@ */ PIXI.glContexts = []; // this is where we store the webGL contexts for easy access. +PIXI.instances = []; /** * The WebGLRenderer draws the stage and all its content onto a webGL enabled canvas. This renderer @@ -82,7 +83,7 @@ PIXI.WebGLRenderer = function(width, height, options) * @type Boolean */ this.preserveDrawingBuffer = options.preserveDrawingBuffer; - + /** * This sets if the WebGLRenderer will clear the context texture or not before the new render pass. If true: * If the Stage is NOT transparent, Pixi will clear to alpha (0, 0, 0, 0). @@ -94,7 +95,7 @@ PIXI.WebGLRenderer = function(width, height, options) * @default */ this.clearBeforeRender = options.clearBeforeRender; - + /** * The width of the canvas view * @@ -251,6 +252,8 @@ PIXI.WebGLRenderer.prototype.initContext = function() PIXI.glContexts[this.glContextId] = gl; + PIXI.instances[this.glContextId] = this; + // set up the default pixi settings.. gl.disable(gl.DEPTH_TEST); gl.disable(gl.CULL_FACE); @@ -295,7 +298,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage) stage.updateTransform(); var gl = this.gl; - + // interaction if(stage._interactive) { @@ -331,10 +334,10 @@ PIXI.WebGLRenderer.prototype.render = function(stage) { gl.clearColor(stage.backgroundColorSplit[0],stage.backgroundColorSplit[1],stage.backgroundColorSplit[2], 1); } - + gl.clear (gl.COLOR_BUFFER_BIT); } - + this.renderDisplayObject( stage, this.projection ); }; @@ -349,7 +352,7 @@ PIXI.WebGLRenderer.prototype.render = function(stage) PIXI.WebGLRenderer.prototype.renderDisplayObject = function(displayObject, projection, buffer) { this.renderSession.blendModeManager.setBlendMode(PIXI.blendModes.NORMAL); - + // reset the render session data.. this.renderSession.drawCount = 0; @@ -416,7 +419,7 @@ PIXI.WebGLRenderer.prototype.updateTexture = function(texture) gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultipliedAlpha); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, texture.source); - + gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, texture.scaleMode === PIXI.scaleModes.LINEAR ? gl.LINEAR : gl.NEAREST); @@ -467,7 +470,7 @@ PIXI.WebGLRenderer.prototype.handleContextRestored = function() var texture = PIXI.TextureCache[key].baseTexture; texture._glTextures = []; } - + this.contextLost = false; }; @@ -536,3 +539,4 @@ PIXI.WebGLRenderer.prototype.mapBlendModes = function() }; PIXI.WebGLRenderer.glContextId = 0; +PIXI.WebGLRenderer.instances = []; diff --git a/src/pixi/renderers/webgl/shaders/PixiShader.js b/src/pixi/renderers/webgl/shaders/PixiShader.js index 725dce2e5..c78752223 100644 --- a/src/pixi/renderers/webgl/shaders/PixiShader.js +++ b/src/pixi/renderers/webgl/shaders/PixiShader.js @@ -16,7 +16,7 @@ PIXI.PixiShader = function(gl) * @private */ this._UID = PIXI._UID++; - + /** * @property gl * @type WebGLContext @@ -82,7 +82,7 @@ PIXI.PixiShader.prototype.constructor = PIXI.PixiShader; /** * Initialises the shader. -* +* * @method init */ PIXI.PixiShader.prototype.init = function() @@ -90,7 +90,7 @@ PIXI.PixiShader.prototype.init = function() var gl = this.gl; var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc); - + gl.useProgram(program); // get and store the uniforms for the shader @@ -133,7 +133,7 @@ PIXI.PixiShader.prototype.init = function() /** * Initialises the shader uniform values. -* +* * Uniforms are specified in the GLSL_ES Specification: http://www.khronos.org/registry/webgl/specs/latest/1.0/ * http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf * @@ -327,7 +327,7 @@ PIXI.PixiShader.prototype.syncUniforms = function() if(uniform.value.baseTexture._dirty[gl.id]) { - PIXI.defaultRenderer.updateTexture(uniform.value.baseTexture); + PIXI.WebGLRenderer.instances[gl.id].updateTexture(uniform.value.baseTexture); } else { @@ -350,7 +350,7 @@ PIXI.PixiShader.prototype.syncUniforms = function() /** * Destroys the shader. -* +* * @method destroy */ PIXI.PixiShader.prototype.destroy = function() @@ -364,7 +364,7 @@ PIXI.PixiShader.prototype.destroy = function() /** * The Default Vertex shader source. -* +* * @property defaultVertexSrc * @type String */ diff --git a/src/pixi/renderers/webgl/utils/WebGLGraphics.js b/src/pixi/renderers/webgl/utils/WebGLGraphics.js index 60eca5bc0..5f8909e83 100644 --- a/src/pixi/renderers/webgl/utils/WebGLGraphics.js +++ b/src/pixi/renderers/webgl/utils/WebGLGraphics.js @@ -309,12 +309,13 @@ PIXI.WebGLGraphics.buildRectangle = function(graphicsData, webGLData) */ PIXI.WebGLGraphics.buildRoundedRectangle = function(graphicsData, webGLData) { - var points = graphicsData.shape.points; - var x = points[0]; - var y = points[1]; - var width = points[2]; - var height = points[3]; - var radius = points[4]; + var rrectData = graphicsData.shape; + var x = rrectData.x; + var y = rrectData.y; + var width = rrectData.width; + var height = rrectData.height; + + var radius = rrectData.radius; var recPoints = []; recPoints.push(x, y + radius); diff --git a/src/pixi/textures/Texture.js b/src/pixi/textures/Texture.js index 02b65138f..c6820db41 100644 --- a/src/pixi/textures/Texture.js +++ b/src/pixi/textures/Texture.js @@ -324,3 +324,6 @@ PIXI.TextureUvs = function() this.x3 = 0; this.y3 = 0; }; + +PIXI.Texture.emptyTexture = new PIXI.Texture(new PIXI.BaseTexture()); + diff --git a/tasks/manifests/pixi.json b/tasks/manifests/pixi.json index 63ca011a7..75b3d46fb 100644 --- a/tasks/manifests/pixi.json +++ b/tasks/manifests/pixi.json @@ -3,6 +3,7 @@ "src/pixi/Pixi.js", "src/pixi/geom/Polygon.js", "src/pixi/geom/Matrix.js", + "src/pixi/geom/RoundedRectangle.js", "src/pixi/display/DisplayObject.js", "src/pixi/display/DisplayObjectContainer.js", "src/pixi/display/Sprite.js",