Skip to content

Commit b4cb281

Browse files
committed
Renamed Phaser.Physics.P2 const to Phaser.Physics.P2JS to avoid issue phaserjs#540
1 parent 79714ac commit b4cb281

3 files changed

Lines changed: 42 additions & 22 deletions

File tree

examples/groups/depth sort.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ var locs = [];
2222
function create() {
2323

2424
// Create our tilemap to walk around
25-
map = game.add.tilemap('desert');
26-
map.addTilesetImage('ground_1x1');
27-
layer = map.createLayer('Tile Layer 1');
25+
// map = game.add.tilemap('desert');
26+
// map.addTilesetImage('ground_1x1');
27+
// layer = map.createLayer('Tile Layer 1');
2828

2929
// This group will hold the main player + all the tree sprites to depth sort against
3030
group = game.add.group();
@@ -35,12 +35,21 @@ function create() {
3535
createUniqueLocation();
3636
}
3737

38+
sprite = group.create(300, 32, 'phaser');
39+
3840
// The player
39-
sprite = group.create(300, 200, 'phaser');
41+
// group.create(128, 0, 'trees', game.rnd.integerInRange(0, 7));
42+
// group.create(64, 0, 'trees', game.rnd.integerInRange(0, 7));
43+
// group.create(256, 0, 'trees', game.rnd.integerInRange(0, 7));
44+
45+
// group.create(128, 32, 'trees', game.rnd.integerInRange(0, 7));
46+
// group.create(64, 32, 'trees', game.rnd.integerInRange(0, 7));
47+
// group.create(256, 32, 'trees', game.rnd.integerInRange(0, 7));
48+
4049

41-
group.sort();
50+
// group.sort();
4251

43-
dump();
52+
// dump();
4453

4554
// group.children[0].alpha = 0.2;
4655
// group.children[100].alpha = 0.2;
@@ -112,5 +121,6 @@ function update() {
112121
function render() {
113122

114123
game.debug.text(sprite.y, 32, 32);
124+
game.debug.text(group.getIndex(sprite), 32, 64);
115125

116126
}

src/core/Group.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,11 +1017,21 @@ Phaser.Group.prototype.forEachDead = function (callback, callbackContext) {
10171017
*/
10181018
Phaser.Group.prototype.sort = function (index, order) {
10191019

1020+
if (this.children.length < 2)
1021+
{
1022+
// Nothing to swap
1023+
return;
1024+
}
1025+
10201026
if (typeof index === 'undefined') { index = 'y'; }
10211027
if (typeof order === 'undefined') { order = Phaser.Group.SORT_ASCENDING; }
10221028

10231029
this._sortProperty = index;
10241030

1031+
this.children.sort(this.ascendingSortHandler.bind(this));
1032+
1033+
1034+
/*
10251035
if (order === Phaser.Group.SORT_ASCENDING)
10261036
{
10271037
this.children.sort(this.ascendingSortHandler.bind(this));
@@ -1030,6 +1040,7 @@ Phaser.Group.prototype.sort = function (index, order) {
10301040
{
10311041
this.children.sort(this.descendingSortHandler.bind(this));
10321042
}
1043+
*/
10331044

10341045
}
10351046

@@ -1042,19 +1053,18 @@ Phaser.Group.prototype.sort = function (index, order) {
10421053
*/
10431054
Phaser.Group.prototype.ascendingSortHandler = function (a, b) {
10441055

1045-
if (a[this._sortProperty] && b[this._sortProperty])
1056+
if (a[this._sortProperty] < b[this._sortProperty] && this.getIndex(a) > this.getIndex(b))
10461057
{
1047-
if (a[this._sortProperty] < b[this._sortProperty])
1048-
{
1049-
return -1;
1050-
}
1051-
else if (a[this._sortProperty] > b[this._sortProperty])
1052-
{
1053-
return 1;
1054-
}
1058+
return -1;
1059+
}
1060+
else if (a[this._sortProperty] > b[this._sortProperty] && this.getIndex(a) < this.getIndex(b))
1061+
{
1062+
return 1;
1063+
}
1064+
else
1065+
{
1066+
return 0;
10551067
}
1056-
1057-
return 0;
10581068

10591069
}
10601070

src/physics/Physics.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Phaser.Physics.ARCADE = 0;
6767
* @const
6868
* @type {number}
6969
*/
70-
Phaser.Physics.P2 = 1;
70+
Phaser.Physics.P2JS = 1;
7171

7272
/**
7373
* @const
@@ -93,7 +93,7 @@ Phaser.Physics.prototype = {
9393
* This will create an instance of the requested physics simulation.
9494
* Phaser.Physics.Arcade is running by default, but all others need activating directly.
9595
* You can start the following physics systems:
96-
* Phaser.Physics.P2 - A full-body advanced physics system by Stefan Hedman.
96+
* Phaser.Physics.P2JS - A full-body advanced physics system by Stefan Hedman.
9797
* Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system.
9898
* Phaser.Physics.BOX2D and Phaser.Physics.CHIPMUNK are still in development.
9999
*
@@ -106,7 +106,7 @@ Phaser.Physics.prototype = {
106106
{
107107
this.arcade = new Phaser.Physics.Arcade(this.game);
108108
}
109-
else if (system === Phaser.Physics.P2 && this.p2 === null)
109+
else if (system === Phaser.Physics.P2JS && this.p2 === null)
110110
{
111111
this.p2 = new Phaser.Physics.P2(this.game, this.config);
112112
}
@@ -131,7 +131,7 @@ Phaser.Physics.prototype = {
131131
* It can be for any of the physics systems that have been started:
132132
*
133133
* Phaser.Physics.Arcade - A light weight AABB based collision system with basic separation.
134-
* Phaser.Physics.P2 - A full-body advanced physics system supporting multiple object shapes, polygon loading, contact materials, springs and constraints.
134+
* Phaser.Physics.P2JS - A full-body advanced physics system supporting multiple object shapes, polygon loading, contact materials, springs and constraints.
135135
* Phaser.Physics.NINJA - A port of Metanet Softwares N+ physics system. Advanced AABB and Circle vs. Tile collision.
136136
* Phaser.Physics.BOX2D and Phaser.Physics.CHIPMUNK are still in development.
137137
*
@@ -171,7 +171,7 @@ Phaser.Physics.prototype = {
171171
{
172172
object[i].body = new Phaser.Physics.Arcade.Body(object[i]);
173173
}
174-
else if (system === Phaser.Physics.P2)
174+
else if (system === Phaser.Physics.P2JS)
175175
{
176176
object[i].body = new Phaser.Physics.P2.Body(this.game, object[i], object[i].x, object[i].y, 1);
177177
object[i].body.debug = debug

0 commit comments

Comments
 (0)