Out of bounds and Sprite events hooked up

This commit is contained in:
Richard Davey
2013-09-09 13:29:33 +01:00
parent ee007cd28e
commit 30fc4099c6
5 changed files with 91 additions and 7 deletions
+8
View File
@@ -32,6 +32,7 @@ Phaser.Group.prototype = {
if (child.group !== this)
{
child.group = this;
child.events.onAddedToGroup.dispatch(child, this);
this._container.addChild(child);
}
@@ -44,6 +45,7 @@ Phaser.Group.prototype = {
if (child.group !== this)
{
child.group = this;
child.events.onAddedToGroup.dispatch(child, this);
this._container.addChildAt(child, index);
}
@@ -61,6 +63,7 @@ Phaser.Group.prototype = {
var child = new Phaser.Sprite(this.game, x, y, key, frame);
child.group = this;
child.events.onAddedToGroup.dispatch(child, this);
this._container.addChild(child);
return child;
@@ -186,11 +189,13 @@ Phaser.Group.prototype = {
{
if (newChild.parent != undefined)
{
newChild.events.onRemovedFromGroup.dispatch(newChild, this);
newChild.parent.removeChild(newChild);
}
this._container.removeChild(oldChild);
this._container.addChildAt(newChild, index);
newChild.events.onAddedToGroup.dispatch(newChild, this);
}
},
@@ -600,6 +605,7 @@ Phaser.Group.prototype = {
remove: function (child) {
child.events.onRemovedFromGroup.dispatch(child, this);
this._container.removeChild(child);
},
@@ -608,6 +614,7 @@ Phaser.Group.prototype = {
do
{
this._container.children[0].events.onRemovedFromGroup.dispatch(this._container.children[0], this);
this._container.removeChild(this._container.children[0]);
}
while (this._container.children.length > 0);
@@ -624,6 +631,7 @@ Phaser.Group.prototype = {
for (var i = startIndex; i < endIndex; i++)
{
var child = this._container.children[i];
child.events.onRemovedFromGroup.dispatch(child, this);
this._container.removeChild(child);
}
+16 -2
View File
@@ -142,6 +142,8 @@ Phaser.Sprite = function (game, x, y, key, frame) {
// Set-up the physics body
this.body = new Phaser.Physics.Arcade.Body(this);
this._outOfBoundsFired = false;
};
// Needed to keep the PIXI.Sprite constructor in the prototype chain (as the core pixi renderer uses an instanceof check sadly)
@@ -270,9 +272,14 @@ Phaser.Sprite.prototype.update = function() {
}
Phaser.Sprite.prototype.postUpdate = function() {
Phaser.Sprite.prototype.reset = function(x, y) {
this.body.postUpdate();
this.x = x;
this.y = y;
this.alive = true;
this.exists = true;
this.visible = true;
this._outOfBoundsFired = false;
}
@@ -299,6 +306,13 @@ Phaser.Sprite.prototype.updateBounds = function() {
this._cache.boundsX = this._cache.x;
this._cache.boundsY = this._cache.y;
// Check world bounds
if (this._outOfBoundsFired == false && Phaser.Rectangle.intersects(this.bounds, this.game.world.bounds, 100) == false)
{
this.events.onOutOfBounds.dispatch(this);
this._outOfBoundsFired = true;
}
}
Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
+1 -1
View File
@@ -381,7 +381,7 @@ Phaser.Input.prototype = {
}
this.currentPointers = 0;
// this.game.stage.canvas.style.cursor = "default";
this.game.stage.canvas.style.cursor = "default";
if (hard == true)
{
+4 -4
View File
@@ -240,10 +240,10 @@ Phaser.Pointer.prototype = {
if (this.game.input.multiInputOverride == Phaser.Input.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.Input.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.Input.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0))
{
//this.game.input.x = this.x * this.game.input.scale.x;
//this.game.input.y = this.y * this.game.input.scale.y;
this.game.input.x = this.x;
this.game.input.y = this.y;
this.game.input.x = this.x * this.game.input.scale.x;
this.game.input.y = this.y * this.game.input.scale.y;
// this.game.input.x = this.x;
// this.game.input.y = this.y;
this.game.input.position.setTo(this.x, this.y);
this.game.input.onDown.dispatch(this);
this.game.input.resetSpeed(this.x, this.y);