Updated to latest Pixi build (can do away with our own local patch now).

Group.sendToBottom(child) is the handy opposite of Group.bringToTop()
Group.moveUp(child) will move a child up the display list, swapping with the child above it.
Group.moveDown(child) will move a child down the display list, swapping with the child below it.
This commit is contained in:
photonstorm
2014-02-28 18:55:07 +00:00
parent bbc0f4a18a
commit 8dcfef8db0
14 changed files with 383 additions and 346 deletions
+77 -3
View File
@@ -213,11 +213,18 @@ Phaser.Group.prototype.addAt = function (child, index) {
*
* @method Phaser.Group#getAt
* @param {number} index - The index to return the child from.
* @return {*} The child that was found at the given index.
* @return {*} The child that was found at the given index. If the index was out of bounds then this will return -1.
*/
Phaser.Group.prototype.getAt = function (index) {
return this.getChildAt(index);
if (index < 0 || index > this.children.length)
{
return -1;
}
else
{
return this.getChildAt(index);
}
}
@@ -352,7 +359,7 @@ Phaser.Group.prototype.swap = function (child1, child2) {
*/
Phaser.Group.prototype.bringToTop = function (child) {
if (child.parent === this)
if (child.parent === this && this.getIndex(child) < this.children.length)
{
this.remove(child);
this.add(child);
@@ -362,6 +369,73 @@ Phaser.Group.prototype.bringToTop = function (child) {
}
/**
* Sends the given child to the bottom of this Group so it renders below all other children.
*
* @method Phaser.Group#sendToBottom
* @param {*} child - The child to send to the bottom of this Group.
* @return {*} The child that was moved.
*/
Phaser.Group.prototype.sendToBottom = function (child) {
if (child.parent === this && this.getIndex(child) > 0)
{
this.remove(child);
this.addAt(child, 0);
}
return child;
}
/**
* Moves the given child up one place in this Group unless it's already at the top.
*
* @method Phaser.Group#moveUp
* @param {*} child - The child to move up in the Group.
* @return {*} The child that was moved.
*/
Phaser.Group.prototype.moveUp = function (child) {
if (child.parent === this && this.getIndex(child) < this.children.length - 1)
{
var a = this.getIndex(child);
var b = this.getAt(a + 1);
if (b)
{
this.swap(a, b);
}
}
return child;
}
/**
* Moves the given child down one place in this Group unless it's already at the top.
*
* @method Phaser.Group#moveDown
* @param {*} child - The child to move down in the Group.
* @return {*} The child that was moved.
*/
Phaser.Group.prototype.moveDown = function (child) {
if (child.parent === this && this.getIndex(child) > 0)
{
var a = this.getIndex(child);
var b = this.getAt(a - 1);
if (b)
{
this.swap(a, b);
}
}
return child;
}
/**
* Get the index position of the given child in this Group.
*
+3
View File
@@ -109,6 +109,9 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
for (var i = 0; i < this.children.length; i++) {
var child = this.children[i];
if(!child.visible)continue;
var texture = child.texture;
var frame = texture.frame;
+38 -57
View File
@@ -6,7 +6,7 @@
* A tiling sprite is a fast way of rendering a tiling image
*
* @class TilingSprite
* @extends DisplayObjectContainer
* @extends Sprite
* @constructor
* @param texture {Texture} the texture of the tiling sprite
* @param width {Number} the width of the tiling sprite
@@ -23,6 +23,7 @@ PIXI.TilingSprite = function(texture, width, height)
* @type Number
*/
this.width = width || 100;
/**
* The height of the tiling sprite
*
@@ -176,58 +177,46 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
var i,j;
if(this.mask || this.filters)
if(this.mask)
{
if(this.mask)
{
renderSession.spriteBatch.stop();
renderSession.maskManager.pushMask(this.mask, renderSession);
renderSession.spriteBatch.start();
}
if(this.filters)
{
renderSession.spriteBatch.flush();
renderSession.filterManager.pushFilter(this._filterBlock);
}
if(!this.tilingTexture || this.refreshTexture)this.generateTilingTexture(true);
else renderSession.spriteBatch.renderTilingSprite(this);
// simple render children!
for(i=0,j=this.children.length; i<j; i++)
{
this.children[i]._renderWebGL(renderSession);
}
renderSession.spriteBatch.stop();
if(this.filters)renderSession.filterManager.popFilter();
if(this.mask)renderSession.maskManager.popMask(renderSession);
renderSession.maskManager.pushMask(this.mask, renderSession);
renderSession.spriteBatch.start();
}
else
if(this.filters)
{
if(!this.tilingTexture || this.refreshTexture)
renderSession.spriteBatch.flush();
renderSession.filterManager.pushFilter(this._filterBlock);
}
if(!this.tilingTexture || this.refreshTexture)
{
this.generateTilingTexture(true);
if(this.tilingTexture && this.tilingTexture.needsUpdate)
{
this.generateTilingTexture(true);
if(this.tilingTexture.needsUpdate)
{
//TODO - tweaking
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
this.tilingTexture.needsUpdate = false;
// this.tilingTexture._uvs = null;
}
}
else renderSession.spriteBatch.renderTilingSprite(this);
// simple render children!
for(i=0,j=this.children.length; i<j; i++)
{
this.children[i]._renderWebGL(renderSession);
//TODO - tweaking
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
this.tilingTexture.needsUpdate = false;
// this.tilingTexture._uvs = null;
}
}
else renderSession.spriteBatch.renderTilingSprite(this);
// simple render children!
for(i=0,j=this.children.length; i<j; i++)
{
this.children[i]._renderWebGL(renderSession);
}
renderSession.spriteBatch.stop();
if(this.filters)renderSession.filterManager.popFilter();
if(this.mask)renderSession.maskManager.popMask(renderSession);
renderSession.spriteBatch.start();
};
/**
@@ -408,17 +397,9 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
{
if(isFrame)
{
if (texture.trim)
{
targetWidth = texture.trim.width;
targetHeight = texture.trim.height;
}
else
{
targetWidth = frame.width;
targetHeight = frame.height;
}
targetWidth = frame.width;
targetHeight = frame.height;
newTextureRequired = true;
}
@@ -451,7 +432,7 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
this.tilingTexture.isTiling = true;
}
canvasBuffer.context.drawImage(texture.baseTexture.source,
frame.x,
frame.y,
@@ -33,7 +33,6 @@ PIXI.PixiShader = function(gl)
'}'
];
/**
* @property {number} textureCount - A local texture counter for multi-texture shaders.
*/
@@ -51,7 +50,6 @@ PIXI.PixiShader = function(gl)
*/
PIXI.PixiShader.prototype.init = function()
{
var gl = this.gl;
var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc);
@@ -305,7 +303,6 @@ PIXI.PixiShader.prototype.syncUniforms = function()
/**
* Destroys the shader
* @method destroy
*
*/
PIXI.PixiShader.prototype.destroy = function()
{
@@ -317,7 +314,7 @@ PIXI.PixiShader.prototype.destroy = function()
};
/**
*
* The Default Vertex shader source
* @property defaultVertexSrc
* @type String
*/
@@ -341,7 +338,3 @@ PIXI.PixiShader.defaultVertexSrc = [
' vColor = vec4(color * aColor.x, aColor.x);',
'}'
];
@@ -122,6 +122,7 @@ PIXI.WebGLFastSpriteBatch.prototype.render = function(spriteBatch)
PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
{
//sprite = children[i];
if(!sprite.visible)return;
// TODO trim??
if(sprite.texture.baseTexture !== this.currentBaseTexture)