Skip to content

Commit 8dcfef8

Browse files
committed
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.
1 parent bbc0f4a commit 8dcfef8

14 files changed

Lines changed: 380 additions & 343 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,9 @@ New features:
128128
* Brand new Grunt task - creates each core library as its own file and a combined phaser.js.
129129
* New build script now cleanly splits Phaser, Pixi and p2 so they are each UMD wrapped and each available in the global scope (now more requireJS friendly!).
130130
* phaser-no-libs.js allows you to use your own version of p2.js or pixi.js with Phaser. Warning: This is totally unsupported. If you hit bugs, you fix them yourself.
131+
* Group.sendToBottom(child) is the handy opposite of Group.bringToTop()
132+
* Group.moveUp(child) will move a child up the display list, swapping with the child above it.
133+
* Group.moveDown(child) will move a child down the display list, swapping with the child below it.
131134

132135

133136
Updates:

build/custom/phaser-no-libs.js

Lines changed: 78 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Phaser - http://www.phaser.io
99
*
10-
* v2.0.0 "Aes Sedai" - Built: Fri Feb 28 2014 09:11:13
10+
* v2.0.0 "Aes Sedai" - Built: Fri Feb 28 2014 18:53:23
1111
*
1212
* By Richard Davey http://www.photonstorm.com @photonstorm
1313
*
@@ -363,66 +363,6 @@ Phaser.Utils = {
363363

364364
};
365365

366-
/**
367-
* Converts a hex color number to an [R, G, B] array
368-
*
369-
* @method hex2rgb
370-
* @param hex {Number}
371-
PIXI.hex2rgb = function(hex) {
372-
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
373-
};
374-
*/
375-
376-
/**
377-
* Converts a color as an [R, G, B] array to a hex number
378-
*
379-
* @method rgb2hex
380-
* @param rgb {Array}
381-
PIXI.rgb2hex = function(rgb) {
382-
return ((rgb[0]*255 << 16) + (rgb[1]*255 << 8) + rgb[2]*255);
383-
};
384-
*/
385-
386-
/**
387-
* Checks whether the Canvas BlendModes are supported by the current browser
388-
*
389-
* @method canUseNewCanvasBlendModes
390-
* @return {Boolean} whether they are supported
391-
PIXI.canUseNewCanvasBlendModes = function()
392-
{
393-
var canvas = document.createElement('canvas');
394-
canvas.width = 1;
395-
canvas.height = 1;
396-
var context = canvas.getContext('2d');
397-
context.fillStyle = '#000';
398-
context.fillRect(0,0,1,1);
399-
context.globalCompositeOperation = 'multiply';
400-
context.fillStyle = '#fff';
401-
context.fillRect(0,0,1,1);
402-
return context.getImageData(0,0,1,1).data[0] === 0;
403-
};
404-
*/
405-
406-
/**
407-
* Given a number, this function returns the closest number that is a power of two
408-
* this function is taken from Starling Framework as its pretty neat ;)
409-
*
410-
* @method getNextPowerOfTwo
411-
* @param number {Number}
412-
* @return {Number} the closest number that is a power of two
413-
PIXI.getNextPowerOfTwo = function(number)
414-
{
415-
if (number > 0 && (number & (number - 1)) === 0) // see: http://goo.gl/D9kPj
416-
return number;
417-
else
418-
{
419-
var result = 1;
420-
while (result < number) result <<= 1;
421-
return result;
422-
}
423-
};
424-
*/
425-
426366
/**
427367
* A polyfill for Function.prototype.bind
428368
*/
@@ -469,7 +409,6 @@ if (!Array.isArray) {
469409
};
470410
}
471411

472-
473412
/**
474413
* @author Richard Davey <rich@photonstorm.com>
475414
* @copyright 2014 Photon Storm Ltd.
@@ -5937,11 +5876,18 @@ Phaser.Group.prototype.addAt = function (child, index) {
59375876
*
59385877
* @method Phaser.Group#getAt
59395878
* @param {number} index - The index to return the child from.
5940-
* @return {*} The child that was found at the given index.
5879+
* @return {*} The child that was found at the given index. If the index was out of bounds then this will return -1.
59415880
*/
59425881
Phaser.Group.prototype.getAt = function (index) {
59435882

5944-
return this.getChildAt(index);
5883+
if (index < 0 || index > this.children.length)
5884+
{
5885+
return -1;
5886+
}
5887+
else
5888+
{
5889+
return this.getChildAt(index);
5890+
}
59455891

59465892
}
59475893

@@ -6076,7 +6022,7 @@ Phaser.Group.prototype.swap = function (child1, child2) {
60766022
*/
60776023
Phaser.Group.prototype.bringToTop = function (child) {
60786024

6079-
if (child.parent === this)
6025+
if (child.parent === this && this.getIndex(child) < this.children.length)
60806026
{
60816027
this.remove(child);
60826028
this.add(child);
@@ -6086,6 +6032,73 @@ Phaser.Group.prototype.bringToTop = function (child) {
60866032

60876033
}
60886034

6035+
/**
6036+
* Sends the given child to the bottom of this Group so it renders below all other children.
6037+
*
6038+
* @method Phaser.Group#sendToBottom
6039+
* @param {*} child - The child to send to the bottom of this Group.
6040+
* @return {*} The child that was moved.
6041+
*/
6042+
Phaser.Group.prototype.sendToBottom = function (child) {
6043+
6044+
if (child.parent === this && this.getIndex(child) > 0)
6045+
{
6046+
this.remove(child);
6047+
this.addAt(child, 0);
6048+
}
6049+
6050+
return child;
6051+
6052+
}
6053+
6054+
/**
6055+
* Moves the given child up one place in this Group unless it's already at the top.
6056+
*
6057+
* @method Phaser.Group#moveUp
6058+
* @param {*} child - The child to move up in the Group.
6059+
* @return {*} The child that was moved.
6060+
*/
6061+
Phaser.Group.prototype.moveUp = function (child) {
6062+
6063+
if (child.parent === this && this.getIndex(child) < this.children.length - 1)
6064+
{
6065+
var a = this.getIndex(child);
6066+
var b = this.getAt(a + 1);
6067+
6068+
if (b)
6069+
{
6070+
this.swap(a, b);
6071+
}
6072+
}
6073+
6074+
return child;
6075+
6076+
}
6077+
6078+
/**
6079+
* Moves the given child down one place in this Group unless it's already at the top.
6080+
*
6081+
* @method Phaser.Group#moveDown
6082+
* @param {*} child - The child to move down in the Group.
6083+
* @return {*} The child that was moved.
6084+
*/
6085+
Phaser.Group.prototype.moveDown = function (child) {
6086+
6087+
if (child.parent === this && this.getIndex(child) > 0)
6088+
{
6089+
var a = this.getIndex(child);
6090+
var b = this.getAt(a - 1);
6091+
6092+
if (b)
6093+
{
6094+
this.swap(a, b);
6095+
}
6096+
}
6097+
6098+
return child;
6099+
6100+
}
6101+
60896102
/**
60906103
* Get the index position of the given child in this Group.
60916104
*

build/custom/phaser-no-libs.min.js

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/custom/pixi.js

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,6 +2160,9 @@ PIXI.SpriteBatch.prototype._renderCanvas = function(renderSession)
21602160
for (var i = 0; i < this.children.length; i++) {
21612161

21622162
var child = this.children[i];
2163+
2164+
if(!child.visible)continue;
2165+
21632166
var texture = child.texture;
21642167
var frame = texture.frame;
21652168

@@ -3453,7 +3456,6 @@ PIXI.PixiShader = function(gl)
34533456
'}'
34543457
];
34553458

3456-
34573459
/**
34583460
* @property {number} textureCount - A local texture counter for multi-texture shaders.
34593461
*/
@@ -3471,7 +3473,6 @@ PIXI.PixiShader = function(gl)
34713473
*/
34723474
PIXI.PixiShader.prototype.init = function()
34733475
{
3474-
34753476
var gl = this.gl;
34763477

34773478
var program = PIXI.compileProgram(gl, this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc);
@@ -3725,7 +3726,6 @@ PIXI.PixiShader.prototype.syncUniforms = function()
37253726
/**
37263727
* Destroys the shader
37273728
* @method destroy
3728-
*
37293729
*/
37303730
PIXI.PixiShader.prototype.destroy = function()
37313731
{
@@ -3737,7 +3737,7 @@ PIXI.PixiShader.prototype.destroy = function()
37373737
};
37383738

37393739
/**
3740-
*
3740+
* The Default Vertex shader source
37413741
* @property defaultVertexSrc
37423742
* @type String
37433743
*/
@@ -3762,10 +3762,6 @@ PIXI.PixiShader.defaultVertexSrc = [
37623762
'}'
37633763
];
37643764

3765-
3766-
3767-
3768-
37693765
/**
37703766
* @author Mat Groves http://matgroves.com/ @Doormat23
37713767
* @author Richard Davey http://www.photonstorm.com @photonstorm
@@ -6084,6 +6080,7 @@ PIXI.WebGLFastSpriteBatch.prototype.render = function(spriteBatch)
60846080
PIXI.WebGLFastSpriteBatch.prototype.renderSprite = function(sprite)
60856081
{
60866082
//sprite = children[i];
6083+
if(!sprite.visible)return;
60876084

60886085
// TODO trim??
60896086
if(sprite.texture.baseTexture !== this.currentBaseTexture)
@@ -8429,7 +8426,7 @@ PIXI.Graphics.ELIP = 3;
84298426
* A tiling sprite is a fast way of rendering a tiling image
84308427
*
84318428
* @class TilingSprite
8432-
* @extends DisplayObjectContainer
8429+
* @extends Sprite
84338430
* @constructor
84348431
* @param texture {Texture} the texture of the tiling sprite
84358432
* @param width {Number} the width of the tiling sprite
@@ -8446,6 +8443,7 @@ PIXI.TilingSprite = function(texture, width, height)
84468443
* @type Number
84478444
*/
84488445
this.width = width || 100;
8446+
84498447
/**
84508448
* The height of the tiling sprite
84518449
*
@@ -8599,58 +8597,46 @@ PIXI.TilingSprite.prototype._renderWebGL = function(renderSession)
85998597

86008598
var i,j;
86018599

8602-
if(this.mask || this.filters)
8600+
if(this.mask)
86038601
{
8604-
if(this.mask)
8605-
{
8606-
renderSession.spriteBatch.stop();
8607-
renderSession.maskManager.pushMask(this.mask, renderSession);
8608-
renderSession.spriteBatch.start();
8609-
}
8602+
renderSession.spriteBatch.stop();
8603+
renderSession.maskManager.pushMask(this.mask, renderSession);
8604+
renderSession.spriteBatch.start();
8605+
}
86108606

8611-
if(this.filters)
8612-
{
8613-
renderSession.spriteBatch.flush();
8614-
renderSession.filterManager.pushFilter(this._filterBlock);
8615-
}
8607+
if(this.filters)
8608+
{
8609+
renderSession.spriteBatch.flush();
8610+
renderSession.filterManager.pushFilter(this._filterBlock);
8611+
}
86168612

8617-
if(!this.tilingTexture || this.refreshTexture)this.generateTilingTexture(true);
8618-
else renderSession.spriteBatch.renderTilingSprite(this);
86198613

8620-
// simple render children!
8621-
for(i=0,j=this.children.length; i<j; i++)
8614+
if(!this.tilingTexture || this.refreshTexture)
8615+
{
8616+
this.generateTilingTexture(true);
8617+
if(this.tilingTexture && this.tilingTexture.needsUpdate)
86228618
{
8623-
this.children[i]._renderWebGL(renderSession);
8619+
//TODO - tweaking
8620+
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
8621+
this.tilingTexture.needsUpdate = false;
8622+
// this.tilingTexture._uvs = null;
86248623
}
8625-
8626-
renderSession.spriteBatch.stop();
8627-
8628-
if(this.filters)renderSession.filterManager.popFilter();
8629-
if(this.mask)renderSession.maskManager.popMask(renderSession);
8630-
8631-
renderSession.spriteBatch.start();
86328624
}
8633-
else
8625+
else renderSession.spriteBatch.renderTilingSprite(this);
8626+
8627+
8628+
// simple render children!
8629+
for(i=0,j=this.children.length; i<j; i++)
86348630
{
8635-
if(!this.tilingTexture || this.refreshTexture)
8636-
{
8637-
this.generateTilingTexture(true);
8638-
if(this.tilingTexture.needsUpdate)
8639-
{
8640-
//TODO - tweaking
8641-
PIXI.updateWebGLTexture(this.tilingTexture.baseTexture, renderSession.gl);
8642-
this.tilingTexture.needsUpdate = false;
8643-
// this.tilingTexture._uvs = null;
8644-
}
8645-
}
8646-
else renderSession.spriteBatch.renderTilingSprite(this);
8647-
8648-
// simple render children!
8649-
for(i=0,j=this.children.length; i<j; i++)
8650-
{
8651-
this.children[i]._renderWebGL(renderSession);
8652-
}
8631+
this.children[i]._renderWebGL(renderSession);
86538632
}
8633+
8634+
renderSession.spriteBatch.stop();
8635+
8636+
if(this.filters)renderSession.filterManager.popFilter();
8637+
if(this.mask)renderSession.maskManager.popMask(renderSession);
8638+
8639+
renderSession.spriteBatch.start();
86548640
};
86558641

86568642
/**
@@ -8831,17 +8817,9 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
88318817
{
88328818
if(isFrame)
88338819
{
8834-
if (texture.trim)
8835-
{
8836-
targetWidth = texture.trim.width;
8837-
targetHeight = texture.trim.height;
8838-
}
8839-
else
8840-
{
8841-
targetWidth = frame.width;
8842-
targetHeight = frame.height;
8843-
}
8844-
8820+
targetWidth = frame.width;
8821+
targetHeight = frame.height;
8822+
88458823
newTextureRequired = true;
88468824

88478825
}
@@ -8874,7 +8852,7 @@ PIXI.TilingSprite.prototype.generateTilingTexture = function(forcePowerOfTwo)
88748852
this.tilingTexture.isTiling = true;
88758853

88768854
}
8877-
8855+
88788856
canvasBuffer.context.drawImage(texture.baseTexture.source,
88798857
frame.x,
88808858
frame.y,

build/custom/pixi.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)