mirror of
https://github.com/wassname/phaser.git
synced 2026-09-09 11:28:47 +08:00
Fixed the Bring to Top bug and also fixed Group/World.swap when the child was a tail node. Also improved Group.dump significantly. Fixed Phaser.Utils namespace clash too.
This commit is contained in:
+39
-12
@@ -6,10 +6,18 @@ Phaser.Group = function (game, parent, name) {
|
||||
this.name = name || 'group';
|
||||
|
||||
this._container = new PIXI.DisplayObjectContainer();
|
||||
this._container.name = this.name;
|
||||
|
||||
if (parent)
|
||||
{
|
||||
parent.addChild(this._container);
|
||||
if (parent instanceof Phaser.Group)
|
||||
{
|
||||
parent._container.addChild(this._container);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.addChild(this._container);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -84,9 +92,9 @@ Phaser.Group.prototype = {
|
||||
var child2Next = child2._iNext;
|
||||
|
||||
var endNode = this._container.last._iNext;
|
||||
var currentNode = this._container.first;
|
||||
var currentNode = this.game.stage._stage;
|
||||
|
||||
do
|
||||
do
|
||||
{
|
||||
if (currentNode !== child1 && currentNode !== child2)
|
||||
{
|
||||
@@ -161,9 +169,10 @@ Phaser.Group.prototype = {
|
||||
|
||||
bringToTop: function (child) {
|
||||
|
||||
if (child !== this._container.last)
|
||||
if (child.group === this)
|
||||
{
|
||||
this.swap(child, this._container.last);
|
||||
this.remove(child);
|
||||
this.add(child);
|
||||
}
|
||||
|
||||
return child;
|
||||
@@ -610,6 +619,7 @@ Phaser.Group.prototype = {
|
||||
|
||||
child.events.onRemovedFromGroup.dispatch(child, this);
|
||||
this._container.removeChild(child);
|
||||
child.group = null;
|
||||
|
||||
},
|
||||
|
||||
@@ -654,15 +664,31 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
dump: function () {
|
||||
dump: function (full) {
|
||||
|
||||
console.log("\nNode\t\t|\t\tNext\t\t|\t\tPrev\t\t|\t\tFirst\t\t|\t\tLast");
|
||||
console.log("\t\t\t|\t\t\t\t\t|\t\t\t\t\t|\t\t\t\t\t|");
|
||||
if (typeof full == 'undefined')
|
||||
{
|
||||
full = false;
|
||||
}
|
||||
|
||||
var displayObject = this._container;
|
||||
var spacing = 20;
|
||||
var output = "\n" + Phaser.Utils.pad('Node', spacing) + "|" + Phaser.Utils.pad('Next', spacing) + "|" + Phaser.Utils.pad('Previous', spacing) + "|" + Phaser.Utils.pad('First', spacing) + "|" + Phaser.Utils.pad('Last', spacing);
|
||||
|
||||
var testObject = displayObject.last._iNext;
|
||||
displayObject = displayObject.first;
|
||||
console.log(output);
|
||||
|
||||
var output = Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing) + "|" + Phaser.Utils.pad('----------', spacing);
|
||||
console.log(output);
|
||||
|
||||
if (full)
|
||||
{
|
||||
var testObject = this.game.stage._stage.last._iNext;
|
||||
var displayObject = this.game.stage._stage;
|
||||
}
|
||||
else
|
||||
{
|
||||
var testObject = this._container.last._iNext;
|
||||
var displayObject = this._container;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
@@ -712,7 +738,8 @@ Phaser.Group.prototype = {
|
||||
nameLast = '-';
|
||||
}
|
||||
|
||||
console.log(name + '\t\t\t|\t\t' + nameNext + '\t\t\t|\t\t' + namePrev + '\t\t\t|\t\t' + nameFirst + '\t\t\t|\t\t' + nameLast);
|
||||
var output = Phaser.Utils.pad(name, spacing) + "|" + Phaser.Utils.pad(nameNext, spacing) + "|" + Phaser.Utils.pad(namePrev, spacing) + "|" + Phaser.Utils.pad(nameFirst, spacing) + "|" + Phaser.Utils.pad(nameLast, spacing);
|
||||
console.log(output);
|
||||
|
||||
displayObject = displayObject._iNext;
|
||||
|
||||
|
||||
+2
-4
@@ -86,10 +86,8 @@ Phaser.World.prototype = {
|
||||
|
||||
bringToTop: function (child) {
|
||||
|
||||
if (child !== this.game.stage._stage.last)
|
||||
{
|
||||
this.swapChildren(child, this.game.stage._stage.last);
|
||||
}
|
||||
this.remove(child);
|
||||
this.add(child);
|
||||
|
||||
return child;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
x = x || 0;
|
||||
y = y || 0;
|
||||
key = key || null; // if null we ought to set to the phaser logo or something :)
|
||||
key = key || null;
|
||||
frame = frame || null;
|
||||
|
||||
this.game = game;
|
||||
|
||||
+6
-2
@@ -391,8 +391,12 @@ Phaser.Cache.prototype = {
|
||||
|
||||
var output = [];
|
||||
|
||||
for (var item in array) {
|
||||
output.push(item);
|
||||
for (var item in array)
|
||||
{
|
||||
if (item !== '__default')
|
||||
{
|
||||
output.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
* @module Phaser
|
||||
*/
|
||||
|
||||
Phaser.Utils = {
|
||||
// Until we have a proper entry-point
|
||||
}
|
||||
|
||||
/**
|
||||
* A collection of methods for displaying debug information about game objects.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
|
||||
Phaser.Utils = {
|
||||
|
||||
/**
|
||||
* Javascript string pad
|
||||
* http://www.webtoolkit.info/
|
||||
* pad = the string to pad it out with (defaults to a space)
|
||||
* dir = 1 (left), 2 (right), 3 (both)
|
||||
**/
|
||||
pad: function (str, len, pad, dir) {
|
||||
|
||||
if (typeof(len) == "undefined") { var len = 0; }
|
||||
if (typeof(pad) == "undefined") { var pad = ' '; }
|
||||
if (typeof(dir) == "undefined") { var dir = 3; }
|
||||
|
||||
if (len + 1 >= str.length)
|
||||
{
|
||||
switch (dir)
|
||||
{
|
||||
case 1:
|
||||
str = Array(len + 1 - str.length).join(pad) + str;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
var right = Math.ceil((padlen = len - str.length) / 2);
|
||||
var left = padlen - right;
|
||||
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
|
||||
break;
|
||||
|
||||
default:
|
||||
str = str + Array(len + 1 - str.length).join(pad);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
|
||||
},
|
||||
|
||||
// This is a slightly modified version of jQuery.isPlainObject
|
||||
isPlainObject: function (obj) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user