mirror of
https://github.com/wassname/phaser.git
synced 2026-07-15 01:11:26 +08:00
Group nearly done. Sprite.anchor appears to be broken though, must fix.
This commit is contained in:
@@ -378,7 +378,6 @@ Phaser.Game.prototype = {
|
||||
if (!this.paused)
|
||||
{
|
||||
this.plugins.preUpdate();
|
||||
// this.world.preUpdate();
|
||||
this.physics.preUpdate();
|
||||
|
||||
this.input.update();
|
||||
@@ -391,9 +390,6 @@ Phaser.Game.prototype = {
|
||||
this.renderer.render(this.world._stage);
|
||||
this.state.render();
|
||||
|
||||
// this.world.postUpdate();
|
||||
// this.physics.postUpdate();
|
||||
|
||||
this.plugins.postRender();
|
||||
}
|
||||
|
||||
|
||||
+320
-56
@@ -1,14 +1,21 @@
|
||||
Phaser.Group = function (game, name) {
|
||||
Phaser.Group = function (game, parent, name) {
|
||||
|
||||
parent = parent || null;
|
||||
|
||||
this.game = game;
|
||||
this.name = name || '';
|
||||
this.name = name || 'group';
|
||||
|
||||
this._container = new PIXI.DisplayObjectContainer();
|
||||
|
||||
// Swap for proper access to stage
|
||||
this.game.world._stage.addChild(this._container);
|
||||
if (parent)
|
||||
{
|
||||
parent.addChild(this._container);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.game.world.add(this._container);
|
||||
}
|
||||
|
||||
this.active = true;
|
||||
this.exists = true;
|
||||
|
||||
/**
|
||||
@@ -44,13 +51,13 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
getChildAt: function (index) {
|
||||
getAt: function (index) {
|
||||
|
||||
return this._container.getChildAt(index);
|
||||
|
||||
},
|
||||
|
||||
createSprite: function (x, y, key, frame) {
|
||||
create: function (x, y, key, frame) {
|
||||
|
||||
var child = new Phaser.Sprite(this.game, x, y, key, frame);
|
||||
child.group = this;
|
||||
@@ -151,7 +158,7 @@ Phaser.Group.prototype = {
|
||||
|
||||
bringToTop: function (child) {
|
||||
|
||||
if (!child === this._container.last)
|
||||
if (child !== this._container.last)
|
||||
{
|
||||
this.swap(child, this._container.last);
|
||||
}
|
||||
@@ -160,7 +167,32 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
replace: function (newChild, oldChild) {
|
||||
getIndex: function (child) {
|
||||
|
||||
return this._container.children.indexOf(child);
|
||||
|
||||
},
|
||||
|
||||
replace: function (oldChild, newChild) {
|
||||
|
||||
if (!this._container.first._iNext)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var index = this.getIndex(oldChild);
|
||||
|
||||
if (index != -1)
|
||||
{
|
||||
if (newChild.parent != undefined)
|
||||
{
|
||||
newChild.parent.removeChild(newChild);
|
||||
}
|
||||
|
||||
this._container.removeChild(oldChild);
|
||||
this._container.addChildAt(newChild, index);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -269,18 +301,21 @@ Phaser.Group.prototype = {
|
||||
checkVisible = checkVisible || false;
|
||||
operation = operation || 0;
|
||||
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
if ((checkAlive == false || (checkAlive && currentNode.alive)) && (checkVisible == false || (checkVisible && currentNode.visible)))
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
this.setProperty(currentNode, key, value, operation);
|
||||
}
|
||||
if ((checkAlive == false || (checkAlive && currentNode.alive)) && (checkVisible == false || (checkVisible && currentNode.visible)))
|
||||
{
|
||||
this.setProperty(currentNode, key, value, operation);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
|
||||
},
|
||||
|
||||
@@ -308,16 +343,125 @@ Phaser.Group.prototype = {
|
||||
|
||||
},
|
||||
|
||||
callAll: function () {
|
||||
/**
|
||||
* Calls a function on all of the active children (children with exists=true).
|
||||
* You must pass the context in which the callback is applied.
|
||||
* After the context you can add as many parameters as you like, which will all be passed to the child.
|
||||
*/
|
||||
callAll: function (callback, callbackContext) {
|
||||
|
||||
var args = Array.prototype.splice.call(arguments, 2);
|
||||
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.exists && currentNode[callback])
|
||||
{
|
||||
currentNode[callback].apply(currentNode, args);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
forEach: function () {
|
||||
forEach: function (callback, callbackContext, checkExists) {
|
||||
|
||||
checkExists = checkExists || false;
|
||||
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (checkExists == false || (checkExists && currentNode.exists))
|
||||
{
|
||||
callback.call(callbackContext, currentNode);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
forEachAlive: function () {
|
||||
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.alive)
|
||||
{
|
||||
callback.call(callbackContext, currentNode);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
forEachDead: function () {
|
||||
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.alive == false)
|
||||
{
|
||||
callback.call(callbackContext, currentNode);
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Call this function to retrieve the first object with exists == (the given state) in the group.
|
||||
*
|
||||
* @return {Any} The first child, or null if none found.
|
||||
*/
|
||||
getFirstExists: function (state) {
|
||||
|
||||
state = state || true;
|
||||
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.exists == state)
|
||||
{
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -328,18 +472,21 @@ Phaser.Group.prototype = {
|
||||
*/
|
||||
getFirstAlive: function () {
|
||||
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
if (currentNode.alive)
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
return currentNode;
|
||||
}
|
||||
if (currentNode.alive)
|
||||
{
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
|
||||
return null;
|
||||
|
||||
@@ -353,18 +500,21 @@ Phaser.Group.prototype = {
|
||||
*/
|
||||
getFirstDead: function () {
|
||||
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
if (!currentNode.alive)
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
return currentNode;
|
||||
}
|
||||
if (!currentNode.alive)
|
||||
{
|
||||
return currentNode;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
}
|
||||
while (currentNode != this._container.last._iNext)
|
||||
|
||||
return null;
|
||||
|
||||
@@ -378,18 +528,22 @@ Phaser.Group.prototype = {
|
||||
countLiving: function () {
|
||||
|
||||
var total = -1;
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.alive)
|
||||
{
|
||||
total++;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (currentNode.alive)
|
||||
{
|
||||
total++;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
|
||||
return total;
|
||||
|
||||
@@ -403,18 +557,22 @@ Phaser.Group.prototype = {
|
||||
countDead: function () {
|
||||
|
||||
var total = -1;
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (!currentNode.alive)
|
||||
{
|
||||
total++;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
if (this._container.first._iNext)
|
||||
{
|
||||
var currentNode = this._container.first._iNext;
|
||||
|
||||
do
|
||||
{
|
||||
if (!currentNode.alive)
|
||||
{
|
||||
total++;
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
}
|
||||
while (currentNode != this._container.last._iNext);
|
||||
|
||||
return total;
|
||||
|
||||
@@ -438,9 +596,115 @@ Phaser.Group.prototype = {
|
||||
},
|
||||
|
||||
remove: function (child) {
|
||||
|
||||
this._container.removeChild(child);
|
||||
|
||||
},
|
||||
|
||||
removeAll: function () {
|
||||
|
||||
do
|
||||
{
|
||||
this._container.removeChild(this._container.children[0]);
|
||||
}
|
||||
while (this._container.children.length > 0);
|
||||
|
||||
},
|
||||
|
||||
removeBetween: function (startIndex, endIndex) {
|
||||
|
||||
if (startIndex > endIndex || startIndex < 0 || endIndex > this._container.children.length)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = startIndex; i < endIndex; i++)
|
||||
{
|
||||
var child = this._container.children[i];
|
||||
this._container.removeChild(child);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
|
||||
this.removeAll();
|
||||
|
||||
this._container.parent.removeChild(this._container);
|
||||
|
||||
this._container = null;
|
||||
|
||||
this.game = null;
|
||||
|
||||
this.exists = false;
|
||||
|
||||
},
|
||||
|
||||
dump: function () {
|
||||
|
||||
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|");
|
||||
|
||||
var displayObject = this._container;
|
||||
|
||||
var testObject = displayObject.last._iNext;
|
||||
displayObject = displayObject.first;
|
||||
|
||||
do
|
||||
{
|
||||
var name = displayObject.name || '*';
|
||||
var nameNext = '-';
|
||||
var namePrev = '-';
|
||||
var nameFirst = '-';
|
||||
var nameLast = '-';
|
||||
|
||||
if (displayObject._iNext)
|
||||
{
|
||||
nameNext = displayObject._iNext.name;
|
||||
}
|
||||
|
||||
if (displayObject._iPrev)
|
||||
{
|
||||
namePrev = displayObject._iPrev.name;
|
||||
}
|
||||
|
||||
if (displayObject.first)
|
||||
{
|
||||
nameFirst = displayObject.first.name;
|
||||
}
|
||||
|
||||
if (displayObject.last)
|
||||
{
|
||||
nameLast = displayObject.last.name;
|
||||
}
|
||||
|
||||
if (typeof nameNext === 'undefined')
|
||||
{
|
||||
nameNext = '-';
|
||||
}
|
||||
|
||||
if (typeof namePrev === 'undefined')
|
||||
{
|
||||
namePrev = '-';
|
||||
}
|
||||
|
||||
if (typeof nameFirst === 'undefined')
|
||||
{
|
||||
nameFirst = '-';
|
||||
}
|
||||
|
||||
if (typeof nameLast === 'undefined')
|
||||
{
|
||||
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);
|
||||
|
||||
displayObject = displayObject._iNext;
|
||||
|
||||
}
|
||||
while(displayObject != testObject)
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -481,7 +745,7 @@ Object.defineProperty(Phaser.Group.prototype, "angle", {
|
||||
|
||||
set: function(value) {
|
||||
this._container.rotation = Phaser.Math.degToRad(value);
|
||||
}
|
||||
},
|
||||
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
|
||||
+23
-43
@@ -5,11 +5,6 @@ Phaser.World = function (game) {
|
||||
this._stage = new PIXI.Stage(0x000000);
|
||||
this._stage.name = '_stage_root';
|
||||
|
||||
this._container = new PIXI.DisplayObjectContainer();
|
||||
// this._container.name = '_stage_root';
|
||||
|
||||
this._stage.addChild(this._container);
|
||||
|
||||
this.bounds = new Phaser.Rectangle(0, 0, game.width, game.height);
|
||||
|
||||
};
|
||||
@@ -17,7 +12,7 @@ Phaser.World = function (game) {
|
||||
Phaser.World.prototype = {
|
||||
|
||||
_stage: null,
|
||||
_container: null,
|
||||
_stage: null,
|
||||
_length: 0,
|
||||
|
||||
bounds: null,
|
||||
@@ -31,66 +26,51 @@ Phaser.World.prototype = {
|
||||
},
|
||||
|
||||
add: function (gameobject) {
|
||||
this._container.addChild(gameobject);
|
||||
|
||||
this._stage.addChild(gameobject);
|
||||
return gameobject;
|
||||
|
||||
},
|
||||
|
||||
addAt: function (gameobject, index) {
|
||||
this._container.addChildAt(gameobject, index);
|
||||
|
||||
this._stage.addChildAt(gameobject, index);
|
||||
return gameobject;
|
||||
|
||||
},
|
||||
|
||||
getAt: function (index) {
|
||||
return this._container.getChildAt(index);
|
||||
|
||||
return this._stage.getChildAt(index);
|
||||
|
||||
},
|
||||
|
||||
remove: function (gameobject) {
|
||||
this._container.removeChild(gameobject);
|
||||
|
||||
this._stage.removeChild(gameobject);
|
||||
return gameobject;
|
||||
|
||||
},
|
||||
|
||||
update: function () {
|
||||
|
||||
this.camera.update();
|
||||
|
||||
// TODO - sort this out, the nodes are wrong
|
||||
var displayObject = this._stage;
|
||||
|
||||
var testObject = displayObject.last._iNext;
|
||||
displayObject = displayObject.first;
|
||||
|
||||
do
|
||||
if (this._stage.first._iNext)
|
||||
{
|
||||
if (displayObject['update'])
|
||||
{
|
||||
displayObject.update();
|
||||
}
|
||||
var currentNode = this._stage.first._iNext;
|
||||
|
||||
// count++
|
||||
displayObject = displayObject._iNext;
|
||||
}
|
||||
while(displayObject != testObject)
|
||||
|
||||
},
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
var displayObject = this._stage;
|
||||
|
||||
var testObject = displayObject.last._iNext;
|
||||
displayObject = displayObject.first;
|
||||
|
||||
do
|
||||
{
|
||||
if (displayObject['postUpdate'])
|
||||
do
|
||||
{
|
||||
displayObject.postUpdate();
|
||||
if (currentNode['update'])
|
||||
{
|
||||
currentNode.update();
|
||||
}
|
||||
|
||||
currentNode = currentNode._iNext;
|
||||
}
|
||||
|
||||
// count++
|
||||
displayObject = displayObject._iNext;
|
||||
while (currentNode != this._stage.last._iNext)
|
||||
}
|
||||
while(displayObject != testObject)
|
||||
|
||||
},
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ Phaser.GameObjectFactory.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Create a new Sprite with specific position and sprite sheet key.
|
||||
* Create a new Sprite with specific position and sprite sheet key that will automatically be added as a child of the given parent.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
@@ -55,6 +55,12 @@ Phaser.GameObjectFactory.prototype = {
|
||||
|
||||
},
|
||||
|
||||
group: function (parent, name) {
|
||||
|
||||
return new Phaser.Group(this.game, parent, name);
|
||||
|
||||
},
|
||||
|
||||
audio: function (key, volume, loop) {
|
||||
|
||||
return this.game.sound.add(key, volume, loop);
|
||||
|
||||
@@ -7,9 +7,13 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
// If exists = false then the Sprite isn't updated by the core game loop or physics subsystem at all
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
|
||||
// An "invisible" sprite isn't rendered at all
|
||||
this.visible = true;
|
||||
|
||||
// This is a handy little var your game can use to determine if a sprite is alive or not, it doesn't effect rendering
|
||||
this.alive = true;
|
||||
|
||||
this.group = null;
|
||||
@@ -144,6 +148,11 @@ Phaser.Sprite.prototype.constructor = Phaser.Sprite;
|
||||
*/
|
||||
Phaser.Sprite.prototype.update = function() {
|
||||
|
||||
if (!this.exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this._cache.dirty = false;
|
||||
|
||||
if (this.animations.update())
|
||||
|
||||
@@ -160,36 +160,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
postUpdate: function () {
|
||||
|
||||
/*
|
||||
// The State update may (almost certainly?) will had
|
||||
|
||||
if (this.collideWorldBounds)
|
||||
{
|
||||
// Adjust sprite directly?
|
||||
this.checkWorldBounds();
|
||||
}
|
||||
|
||||
console.log('pre pu', this.x, this.y);
|
||||
|
||||
// if (this.moves)
|
||||
// {
|
||||
this.sprite.x = this.x - this.offset.x + (this.sprite.anchor.x * this.width);
|
||||
this.sprite.y = this.y - this.offset.y + (this.sprite.anchor.y * this.height);
|
||||
// }
|
||||
|
||||
console.log('post pu', this.sprite.x, this.sprite.y);
|
||||
|
||||
if (this.allowRotation)
|
||||
{
|
||||
this.sprite.angle = this.rotation;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
},
|
||||
|
||||
setSize: function (width, height, offsetX, offsetY) {
|
||||
|
||||
offsetX = offsetX || this.offset.x;
|
||||
@@ -207,60 +177,6 @@ Phaser.Physics.Arcade.Body.prototype = {
|
||||
|
||||
},
|
||||
|
||||
/*
|
||||
hullWidth: function () {
|
||||
|
||||
if (this.deltaX() > 0)
|
||||
{
|
||||
return this.width + this.deltaX();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.width - this.deltaX();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullHeight: function () {
|
||||
|
||||
if (this.deltaY() > 0)
|
||||
{
|
||||
return this.height + this.deltaY();
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.height - this.deltaY();
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullX: function () {
|
||||
|
||||
if (this.x < this.lastX)
|
||||
{
|
||||
return this.x;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.lastX;
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
hullY: function () {
|
||||
|
||||
if (this.y < this.lastY)
|
||||
{
|
||||
return this.y;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.lastY;
|
||||
}
|
||||
|
||||
},
|
||||
*/
|
||||
|
||||
deltaAbsX: function () {
|
||||
return (this.deltaX() > 0 ? this.deltaX() : -this.deltaX());
|
||||
},
|
||||
|
||||
+8
-3
@@ -311,15 +311,20 @@ Phaser.Tween.prototype = {
|
||||
|
||||
this._startTime = time + this._delayTime;
|
||||
|
||||
this.onComplete.dispatch(this._object);
|
||||
|
||||
if ( this._onCompleteCallback !== null ) {
|
||||
this._onCompleteCallback.call( this._object );
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
} else {
|
||||
|
||||
this.onComplete.dispatch(this._object);
|
||||
|
||||
if ( this._onCompleteCallback !== null ) {
|
||||
|
||||
this.onComplete.dispatch(this._object);
|
||||
this._onCompleteCallback.call( this._object );
|
||||
|
||||
}
|
||||
|
||||
for ( var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i ++ ) {
|
||||
|
||||
Reference in New Issue
Block a user