mirror of
https://github.com/wassname/phaser.git
synced 2026-07-05 17:30:19 +08:00
Out of bounds and Sprite events hooked up
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user