Skip to content

Commit 4ed20e0

Browse files
committed
Removed all intances of Sprite.group from Group and replaced with the already existing parent property.
1 parent e88b103 commit 4ed20e0

5 files changed

Lines changed: 40 additions & 62 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ Significant API changes:
6363

6464
* Upgraded to Pixi.js 1.4.4
6565
* Group now extends PIXI.DisplayObjectContainer, rather than owning a _container property, which makes life a whole lot easier re: nesting.
66+
* Removed Sprite.group property. You can use Sprite.parent for all similar needs now.
67+
* PIXI.Point is now aliased to Phaser.Point - saves on code duplication and works exactly the same.
68+
* PIXI.Rectangle is now aliased to Phaser.Rectangle - saves on code duplication and works exactly the same.
69+
* PIXI.Circle is now aliased to Phaser.Circle - saves on code duplication and works exactly the same.
6670

6771

6872
New features:

examples/wip/pixi1.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
2+
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
33

44
function preload() {
55

@@ -16,9 +16,9 @@ function create() {
1616

1717
sprite = game.add.sprite(0, 0, 'pic');
1818

19-
g = game.add.group();
19+
g = game.add.group(null, 'billy');
2020

21-
g.create(0, 0, 'pic');
21+
sprite2 = g.create(0, 0, 'pic');
2222

2323
g.y = 200;
2424
g.rotation = 0.1;
@@ -47,4 +47,6 @@ function update() {
4747

4848
function render() {
4949

50+
game.debug.renderText(sprite.position.y, 32, 32);
51+
5052
}

src/core/Group.js

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ Phaser.Group = function (game, parent, name, useStage) {
6868
this.exists = true;
6969

7070
/**
71-
* @property {Phaser.Group} group - The parent Group of this Group, if a child of another.
71+
* @property {Phaser.Group|Phaser.Sprite} parent - The parent of this Group.
7272
*/
73-
this.group = null;
73+
// this.group = null;
7474

7575
/**
7676
* @property {Phaser.Point} scale - The scale of the Group container.
@@ -140,10 +140,8 @@ Phaser.Group.SORT_DESCENDING = 1;
140140
*/
141141
Phaser.Group.prototype.add = function (child) {
142142

143-
if (child.group !== this)
143+
if (child.parent !== this)
144144
{
145-
child.group = this;
146-
147145
this.addChild(child);
148146

149147
if (child.events)
@@ -172,10 +170,8 @@ Phaser.Group.prototype.add = function (child) {
172170
*/
173171
Phaser.Group.prototype.addAt = function (child, index) {
174172

175-
if (child.group !== this)
173+
if (child.parent !== this)
176174
{
177-
child.group = this;
178-
179175
this.addChildAt(child, index);
180176

181177
if (child.events)
@@ -224,7 +220,6 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
224220

225221
var child = new Phaser.Sprite(this.game, x, y, key, frame);
226222

227-
child.group = this;
228223
child.exists = exists;
229224
child.visible = exists;
230225
child.alive = exists;
@@ -262,25 +257,7 @@ Phaser.Group.prototype.createMultiple = function (quantity, key, frame, exists)
262257

263258
for (var i = 0; i < quantity; i++)
264259
{
265-
var child = new Phaser.Sprite(this.game, 0, 0, key, frame);
266-
267-
child.group = this;
268-
child.exists = exists;
269-
child.visible = exists;
270-
child.alive = exists;
271-
272-
this.addChild(child);
273-
274-
if (child.events)
275-
{
276-
child.events.onAddedToGroup.dispatch(child, this);
277-
}
278-
279-
if (this.cursor === null)
280-
{
281-
this.cursor = child;
282-
}
283-
260+
this.create(0, 0, key, frame, exists);
284261
}
285262

286263
}
@@ -343,12 +320,7 @@ Phaser.Group.prototype.previous = function () {
343320
*/
344321
Phaser.Group.prototype.swap = function (child1, child2) {
345322

346-
if (child1 === child2 || !child1.parent || !child2.parent || child1.group !== this || child2.group !== this)
347-
{
348-
return false;
349-
}
350-
351-
this.swapChildren(child1, child2);
323+
return this.swapChildren(child1, child2);
352324

353325
}
354326

@@ -361,7 +333,7 @@ Phaser.Group.prototype.swap = function (child1, child2) {
361333
*/
362334
Phaser.Group.prototype.bringToTop = function (child) {
363335

364-
if (child.group === this)
336+
if (child.parent === this)
365337
{
366338
this.remove(child);
367339
this.add(child);
@@ -473,8 +445,6 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
473445
else if (operation == 3) { child[key[0]][key[1]][key[2]][key[3]] *= value; }
474446
else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; }
475447
}
476-
477-
// TODO - Deep property scane
478448

479449
}
480450

@@ -996,29 +966,23 @@ Phaser.Group.prototype.getRandom = function (startIndex, length) {
996966
*/
997967
Phaser.Group.prototype.remove = function (child) {
998968

999-
if (child.group !== this)
969+
if (this.children.length === 0)
1000970
{
1001-
return false;
971+
return;
1002972
}
1003973

1004974
if (child.events)
1005975
{
1006976
child.events.onRemovedFromGroup.dispatch(child, this);
1007977
}
1008978

1009-
// Check it's actually in the container
1010-
if (child.parent === this)
1011-
{
1012-
this.removeChild(child);
1013-
}
979+
this.removeChild(child);
1014980

1015981
if (this.cursor === child)
1016982
{
1017983
this.next();
1018984
}
1019985

1020-
child.group = null;
1021-
1022986
return true;
1023987

1024988
}
@@ -1042,6 +1006,7 @@ Phaser.Group.prototype.removeAll = function () {
10421006
{
10431007
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
10441008
}
1009+
10451010
this.removeChild(this.children[0]);
10461011
}
10471012
while (this.children.length > 0);
@@ -1071,9 +1036,12 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex) {
10711036

10721037
for (var i = startIndex; i < endIndex; i++)
10731038
{
1074-
var child = this.children[i];
1075-
child.events.onRemovedFromGroup.dispatch(child, this);
1076-
this.removeChild(child);
1039+
if (this.children[i].events)
1040+
{
1041+
this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);
1042+
}
1043+
1044+
this.removeChild(this.children[i]);
10771045

10781046
if (this.cursor === child)
10791047
{

src/gameobjects/Sprite.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
4545
this.alive = true;
4646

4747
/**
48-
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
48+
* @property {Phaser.Group|Phaser.Sprite} parent - The parent of this Sprite.
4949
*/
50-
this.group = null;
50+
// this.group = null;
5151

5252
/**
5353
* @property {string} name - The user defined name given to this Sprite.
@@ -169,7 +169,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
169169
*
170170
* @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
171171
*/
172-
this.anchor = new Phaser.Point();
172+
// this.anchor = new Phaser.Point();
173+
174+
// this.position.x = x;
175+
// this.position.y = y;
173176

174177
/**
175178
* @property {number} x - The x coordinate in world space of this Sprite.
@@ -181,8 +184,6 @@ Phaser.Sprite = function (game, x, y, key, frame) {
181184
*/
182185
this.y = y;
183186

184-
this.position.x = x;
185-
this.position.y = y;
186187

187188
/**
188189
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
@@ -201,7 +202,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
201202
/**
202203
* @property {Phaser.Point} scale - The scale of the Sprite when rendered. By default it's set to 1 (no scale). You can modify it via scale.x or scale.y or scale.setTo(x, y). A value of 1 means no change to the scale, 0.5 means "half the size", 2 means "twice the size", etc.
203204
*/
204-
this.scale = new Phaser.Point(1, 1);
205+
// this.scale = new Phaser.Point(1, 1);
205206

206207
/**
207208
* @property {object} _cache - A mini cache for storing all of the calculated values.
@@ -381,7 +382,7 @@ Phaser.Sprite = function (game, x, y, key, frame) {
381382
this.updateBounds();
382383

383384
/**
384-
* @property {PIXI.Point} pivot - The pivot point of the displayObject that it rotates around.
385+
* @property {Phaser.Point} pivot - The pivot point of the displayObject that it rotates around.
385386
*/
386387

387388
};
@@ -400,7 +401,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
400401

401402
if (this._cache.fresh)
402403
{
403-
this.world.setTo(this.parent.position.x + this.x, this.parent.position.y + this.y);
404+
this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y);
404405
this.worldTransform[2] = this.world.x;
405406
this.worldTransform[5] = this.world.y;
406407
this._cache.fresh = false;
@@ -871,9 +872,9 @@ Phaser.Sprite.prototype.destroy = function() {
871872
this.filters = null;
872873
}
873874

874-
if (this.group)
875+
if (this.parent)
875876
{
876-
this.group.remove(this);
877+
this.parent.remove(this);
877878
}
878879

879880
if (this.input)

src/pixi/display/DisplayObject.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ PIXI.DisplayObject = function()
196196
*/
197197
this._mask = null;
198198

199+
this.x = this.position.x;
200+
this.y = this.position.y;
201+
199202
/*
200203
* MOUSE Callbacks
201204
*/

0 commit comments

Comments
 (0)