mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 05:03:37 +00:00
Removed all intances of Sprite.group from Group and replaced with the already existing parent property.
This commit is contained in:
parent
e88b10323a
commit
4ed20e0f77
5 changed files with 40 additions and 62 deletions
|
@ -63,6 +63,10 @@ Significant API changes:
|
||||||
|
|
||||||
* Upgraded to Pixi.js 1.4.4
|
* Upgraded to Pixi.js 1.4.4
|
||||||
* Group now extends PIXI.DisplayObjectContainer, rather than owning a _container property, which makes life a whole lot easier re: nesting.
|
* Group now extends PIXI.DisplayObjectContainer, rather than owning a _container property, which makes life a whole lot easier re: nesting.
|
||||||
|
* Removed Sprite.group property. You can use Sprite.parent for all similar needs now.
|
||||||
|
* PIXI.Point is now aliased to Phaser.Point - saves on code duplication and works exactly the same.
|
||||||
|
* PIXI.Rectangle is now aliased to Phaser.Rectangle - saves on code duplication and works exactly the same.
|
||||||
|
* PIXI.Circle is now aliased to Phaser.Circle - saves on code duplication and works exactly the same.
|
||||||
|
|
||||||
|
|
||||||
New features:
|
New features:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
||||||
|
|
||||||
function preload() {
|
function preload() {
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ function create() {
|
||||||
|
|
||||||
sprite = game.add.sprite(0, 0, 'pic');
|
sprite = game.add.sprite(0, 0, 'pic');
|
||||||
|
|
||||||
g = game.add.group();
|
g = game.add.group(null, 'billy');
|
||||||
|
|
||||||
g.create(0, 0, 'pic');
|
sprite2 = g.create(0, 0, 'pic');
|
||||||
|
|
||||||
g.y = 200;
|
g.y = 200;
|
||||||
g.rotation = 0.1;
|
g.rotation = 0.1;
|
||||||
|
@ -47,4 +47,6 @@ function update() {
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
|
|
||||||
|
game.debug.renderText(sprite.position.y, 32, 32);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,9 +68,9 @@ Phaser.Group = function (game, parent, name, useStage) {
|
||||||
this.exists = true;
|
this.exists = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Group} group - The parent Group of this Group, if a child of another.
|
* @property {Phaser.Group|Phaser.Sprite} parent - The parent of this Group.
|
||||||
*/
|
*/
|
||||||
this.group = null;
|
// this.group = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Point} scale - The scale of the Group container.
|
* @property {Phaser.Point} scale - The scale of the Group container.
|
||||||
|
@ -140,10 +140,8 @@ Phaser.Group.SORT_DESCENDING = 1;
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.add = function (child) {
|
Phaser.Group.prototype.add = function (child) {
|
||||||
|
|
||||||
if (child.group !== this)
|
if (child.parent !== this)
|
||||||
{
|
{
|
||||||
child.group = this;
|
|
||||||
|
|
||||||
this.addChild(child);
|
this.addChild(child);
|
||||||
|
|
||||||
if (child.events)
|
if (child.events)
|
||||||
|
@ -172,10 +170,8 @@ Phaser.Group.prototype.add = function (child) {
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.addAt = function (child, index) {
|
Phaser.Group.prototype.addAt = function (child, index) {
|
||||||
|
|
||||||
if (child.group !== this)
|
if (child.parent !== this)
|
||||||
{
|
{
|
||||||
child.group = this;
|
|
||||||
|
|
||||||
this.addChildAt(child, index);
|
this.addChildAt(child, index);
|
||||||
|
|
||||||
if (child.events)
|
if (child.events)
|
||||||
|
@ -224,7 +220,6 @@ Phaser.Group.prototype.create = function (x, y, key, frame, exists) {
|
||||||
|
|
||||||
var child = new Phaser.Sprite(this.game, x, y, key, frame);
|
var child = new Phaser.Sprite(this.game, x, y, key, frame);
|
||||||
|
|
||||||
child.group = this;
|
|
||||||
child.exists = exists;
|
child.exists = exists;
|
||||||
child.visible = exists;
|
child.visible = exists;
|
||||||
child.alive = exists;
|
child.alive = exists;
|
||||||
|
@ -262,25 +257,7 @@ Phaser.Group.prototype.createMultiple = function (quantity, key, frame, exists)
|
||||||
|
|
||||||
for (var i = 0; i < quantity; i++)
|
for (var i = 0; i < quantity; i++)
|
||||||
{
|
{
|
||||||
var child = new Phaser.Sprite(this.game, 0, 0, key, frame);
|
this.create(0, 0, key, frame, exists);
|
||||||
|
|
||||||
child.group = this;
|
|
||||||
child.exists = exists;
|
|
||||||
child.visible = exists;
|
|
||||||
child.alive = exists;
|
|
||||||
|
|
||||||
this.addChild(child);
|
|
||||||
|
|
||||||
if (child.events)
|
|
||||||
{
|
|
||||||
child.events.onAddedToGroup.dispatch(child, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.cursor === null)
|
|
||||||
{
|
|
||||||
this.cursor = child;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -343,12 +320,7 @@ Phaser.Group.prototype.previous = function () {
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.swap = function (child1, child2) {
|
Phaser.Group.prototype.swap = function (child1, child2) {
|
||||||
|
|
||||||
if (child1 === child2 || !child1.parent || !child2.parent || child1.group !== this || child2.group !== this)
|
return this.swapChildren(child1, child2);
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.swapChildren(child1, child2);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,7 +333,7 @@ Phaser.Group.prototype.swap = function (child1, child2) {
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.bringToTop = function (child) {
|
Phaser.Group.prototype.bringToTop = function (child) {
|
||||||
|
|
||||||
if (child.group === this)
|
if (child.parent === this)
|
||||||
{
|
{
|
||||||
this.remove(child);
|
this.remove(child);
|
||||||
this.add(child);
|
this.add(child);
|
||||||
|
@ -474,8 +446,6 @@ Phaser.Group.prototype.setProperty = function (child, key, value, operation) {
|
||||||
else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; }
|
else if (operation == 4) { child[key[0]][key[1]][key[2]][key[3]] /= value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - Deep property scane
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -996,9 +966,9 @@ Phaser.Group.prototype.getRandom = function (startIndex, length) {
|
||||||
*/
|
*/
|
||||||
Phaser.Group.prototype.remove = function (child) {
|
Phaser.Group.prototype.remove = function (child) {
|
||||||
|
|
||||||
if (child.group !== this)
|
if (this.children.length === 0)
|
||||||
{
|
{
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (child.events)
|
if (child.events)
|
||||||
|
@ -1006,19 +976,13 @@ Phaser.Group.prototype.remove = function (child) {
|
||||||
child.events.onRemovedFromGroup.dispatch(child, this);
|
child.events.onRemovedFromGroup.dispatch(child, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check it's actually in the container
|
this.removeChild(child);
|
||||||
if (child.parent === this)
|
|
||||||
{
|
|
||||||
this.removeChild(child);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.cursor === child)
|
if (this.cursor === child)
|
||||||
{
|
{
|
||||||
this.next();
|
this.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
child.group = null;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1042,6 +1006,7 @@ Phaser.Group.prototype.removeAll = function () {
|
||||||
{
|
{
|
||||||
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
|
this.children[0].events.onRemovedFromGroup.dispatch(this.children[0], this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.removeChild(this.children[0]);
|
this.removeChild(this.children[0]);
|
||||||
}
|
}
|
||||||
while (this.children.length > 0);
|
while (this.children.length > 0);
|
||||||
|
@ -1071,9 +1036,12 @@ Phaser.Group.prototype.removeBetween = function (startIndex, endIndex) {
|
||||||
|
|
||||||
for (var i = startIndex; i < endIndex; i++)
|
for (var i = startIndex; i < endIndex; i++)
|
||||||
{
|
{
|
||||||
var child = this.children[i];
|
if (this.children[i].events)
|
||||||
child.events.onRemovedFromGroup.dispatch(child, this);
|
{
|
||||||
this.removeChild(child);
|
this.children[i].events.onRemovedFromGroup.dispatch(this.children[i], this);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.removeChild(this.children[i]);
|
||||||
|
|
||||||
if (this.cursor === child)
|
if (this.cursor === child)
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,9 +45,9 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||||
this.alive = true;
|
this.alive = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Group} group - The parent Group of this Sprite. This is usually set after Sprite instantiation by the parent.
|
* @property {Phaser.Group|Phaser.Sprite} parent - The parent of this Sprite.
|
||||||
*/
|
*/
|
||||||
this.group = null;
|
// this.group = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {string} name - The user defined name given to this Sprite.
|
* @property {string} name - The user defined name given to this Sprite.
|
||||||
|
@ -169,7 +169,10 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||||
*
|
*
|
||||||
* @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
|
* @property {Phaser.Point} anchor - The anchor around which rotation and scaling takes place.
|
||||||
*/
|
*/
|
||||||
this.anchor = new Phaser.Point();
|
// this.anchor = new Phaser.Point();
|
||||||
|
|
||||||
|
// this.position.x = x;
|
||||||
|
// this.position.y = y;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {number} x - The x coordinate in world space of this Sprite.
|
* @property {number} x - The x coordinate in world space of this Sprite.
|
||||||
|
@ -181,8 +184,6 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||||
*/
|
*/
|
||||||
this.y = y;
|
this.y = y;
|
||||||
|
|
||||||
this.position.x = x;
|
|
||||||
this.position.y = y;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {Phaser.Point} world - The world coordinates of this Sprite. This differs from the x/y coordinates which are relative to the Sprites container.
|
* @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) {
|
||||||
/**
|
/**
|
||||||
* @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.
|
* @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.
|
||||||
*/
|
*/
|
||||||
this.scale = new Phaser.Point(1, 1);
|
// this.scale = new Phaser.Point(1, 1);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {object} _cache - A mini cache for storing all of the calculated values.
|
* @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) {
|
||||||
this.updateBounds();
|
this.updateBounds();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property {PIXI.Point} pivot - The pivot point of the displayObject that it rotates around.
|
* @property {Phaser.Point} pivot - The pivot point of the displayObject that it rotates around.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -400,7 +401,7 @@ Phaser.Sprite.prototype.preUpdate = function() {
|
||||||
|
|
||||||
if (this._cache.fresh)
|
if (this._cache.fresh)
|
||||||
{
|
{
|
||||||
this.world.setTo(this.parent.position.x + this.x, this.parent.position.y + this.y);
|
this.world.setTo(this.parent.position.x + this.position.x, this.parent.position.y + this.position.y);
|
||||||
this.worldTransform[2] = this.world.x;
|
this.worldTransform[2] = this.world.x;
|
||||||
this.worldTransform[5] = this.world.y;
|
this.worldTransform[5] = this.world.y;
|
||||||
this._cache.fresh = false;
|
this._cache.fresh = false;
|
||||||
|
@ -871,9 +872,9 @@ Phaser.Sprite.prototype.destroy = function() {
|
||||||
this.filters = null;
|
this.filters = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.group)
|
if (this.parent)
|
||||||
{
|
{
|
||||||
this.group.remove(this);
|
this.parent.remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.input)
|
if (this.input)
|
||||||
|
|
|
@ -196,6 +196,9 @@ PIXI.DisplayObject = function()
|
||||||
*/
|
*/
|
||||||
this._mask = null;
|
this._mask = null;
|
||||||
|
|
||||||
|
this.x = this.position.x;
|
||||||
|
this.y = this.position.y;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MOUSE Callbacks
|
* MOUSE Callbacks
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue