diff --git a/examples/wip/sort.js b/examples/wip/sort.js index 9b39682c..4f641237 100644 --- a/examples/wip/sort.js +++ b/examples/wip/sort.js @@ -25,7 +25,7 @@ function create() { for (var i = 0; i < 10; i++) { - var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36)); + var c = group.create(game.world.randomX, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36)); c.name = 'veg' + i; } @@ -37,8 +37,9 @@ function create() { function sortGroup () { console.log('%c ', 'background: #efefef'); + // group.dump(true); group.sort(); - group.dump(false); + // group.dump(true); } @@ -76,7 +77,7 @@ function update() { function render() { - // game.debug.renderText(group.cursor.name, 32, 32); + game.debug.renderText(sprite.y, 32, 32); // game.debug.renderInputInfo(32, 32); } \ No newline at end of file diff --git a/examples/wip/swap.js b/examples/wip/swap.js index ab0de747..cc330394 100644 --- a/examples/wip/swap.js +++ b/examples/wip/swap.js @@ -19,9 +19,9 @@ function create() { group = game.add.group(); - for (var i = 0; i < 10; i++) + for (var i = 0; i < 500; i++) { - var c = group.create(100 + Math.random() * 700, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36)); + var c = group.create(game.world.randomX, game.world.randomY, 'veggies', game.rnd.integerInRange(0, 36)); c.name = 'veg' + i; } @@ -53,9 +53,9 @@ function update() { if (a.name !== b.name) { - console.log('************************ NEW ROUND *********************'); - group.dump(true); - console.log('Group Size: ' + group.length); + // console.log('************************ NEW ROUND *********************'); + // group.dump(true); + // console.log('Group Size: ' + group.length); group.swap(a, b); swapCount++; @@ -77,7 +77,7 @@ function update() { } - time = game.time.now + 100; + // time = game.time.now + 50; } } diff --git a/src/core/Group.js b/src/core/Group.js index 2b1c7c4d..8b6f8fc3 100644 --- a/src/core/Group.js +++ b/src/core/Group.js @@ -388,7 +388,7 @@ Phaser.Group.prototype = { if (child1 === child2 || !child1.parent || !child2.parent) { - console.log('cannot swap these') + console.log('aborting'); return false; } @@ -402,13 +402,13 @@ Phaser.Group.prototype = { var endNode = this._container.last; var currentNode = this.game.stage._stage; - console.log('start do while. start node: ', currentNode.name); - console.log(typeof endNode); + // console.log('start do while. start node: ', currentNode.name); + // console.log(typeof endNode); - if (endNode) - { - console.log('end node: ', endNode.name); - } + // if (endNode) + // { + // console.log('end node: ', endNode.name); + // } do { @@ -437,14 +437,12 @@ Phaser.Group.prototype = { } while (currentNode != endNode) - console.log('end do while'); - if (child1._iNext == child2) { // This is a downward (A to B) neighbour swap - console.log('downward A to B'); - this.childTest('1', child1); - this.childTest('2', child2); + // console.log('downward A to B'); + // this.childTest('1', child1); + // this.childTest('2', child2); child1._iNext = child2Next; child1._iPrev = child2; @@ -469,9 +467,9 @@ Phaser.Group.prototype = { else if (child2._iNext == child1) { // This is an upward (B to A) neighbour swap - console.log('upward B to A'); - this.childTest('1', child1); - this.childTest('2', child2); + // console.log('upward B to A'); + // this.childTest('1', child1); + // this.childTest('2', child2); child1._iNext = child2; child1._iPrev = child2Prev; @@ -496,10 +494,10 @@ Phaser.Group.prototype = { else { // Children are far apart - console.log('far apart A to B'); + // console.log('far apart A to B'); - this.childTest('1', child1); - this.childTest('2', child2); + // this.childTest('1', child1); + // this.childTest('2', child2); child1._iNext = child2Next; child1._iPrev = child2Prev; @@ -1032,6 +1030,8 @@ Phaser.Group.prototype = { console.log('-vvv--------------------------------------------------------------------------------'); + this.dump(true); + for (var i = 0; i < this._sortCache.length; i++) { console.log(i + ' = ' + this._sortCache[i].name + ' at y: ' + this._sortCache[i].y); @@ -1041,6 +1041,8 @@ Phaser.Group.prototype = { this._sortCache.sort(this.sortHandler.bind(this)); + // Should do an array compare here, no need to rebuild the display list if the arrays are the same + for (var i = 0; i < this._sortCache.length; i++) { console.log(i + ' = ' + this._sortCache[i].name + ' at y: ' + this._sortCache[i].y); @@ -1048,11 +1050,11 @@ Phaser.Group.prototype = { for (var i = 0; i < this._sortCache.length; i++) { - if (this._container.children[i] !== this._sortCache[i]) - { - console.log('swapped:', this._container.children[i].name,'with',this._sortCache[i].name); + // if (this._container.children[i] !== this._sortCache[i]) + // { + // console.log('swapped:', this._container.children[i].name,'with',this._sortCache[i].name); this.swap(this._container.children[i], this._sortCache[i]); - } + // } } // Now put it back again @@ -1060,6 +1062,8 @@ Phaser.Group.prototype = { this._container.updateTransform(); + this.dump(true); + console.log('-^^^--------------------------------------------------------------------------------'); },