diff --git a/README.md b/README.md index e84038c82..25444cee0 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,8 @@ Version 1.0.7 (in progress in the dev branch) * Tweens .to will now always return the parent (thanks powerfear) * You can now pass a PIXI.Texture to Sprite (you also need to pass a Phaser.Frame as the frame parameter) but this is useful for Sprites sharing joint canvases. * Fixed Issue #101 (Mouse Button 0 is not recognised, thanks rezoner) +* Added Sprite.destroy back in again and made it a lot more robust at cleaning up child objects. + * TODO: look at Sprite.crop (http://www.html5gamedevs.com/topic/1617-error-in-spritecrop/) diff --git a/examples/tilemaps/wip1.php b/examples/tilemaps/wip1.php index e610a99a5..eae717d7e 100644 --- a/examples/tilemaps/wip1.php +++ b/examples/tilemaps/wip1.php @@ -50,9 +50,10 @@ // layer.sprite.scale.setTo(2, 2); - game.add.sprite(320, 0, layer.texture, layer.frame); - game.add.sprite(0, 200, layer.texture, layer.frame); - game.add.sprite(320, 200, layer.texture, layer.frame); + // Works a treat :) + // game.add.sprite(320, 0, layer.texture, layer.frame); + // game.add.sprite(0, 200, layer.texture, layer.frame); + // game.add.sprite(320, 200, layer.texture, layer.frame); cursors = game.input.keyboard.createCursorKeys(); } diff --git a/src/gameobjects/Events.js b/src/gameobjects/Events.js index e1e3c85df..1cd1b9e90 100644 --- a/src/gameobjects/Events.js +++ b/src/gameobjects/Events.js @@ -34,4 +34,36 @@ Phaser.Events = function (sprite) { this.onAnimationComplete = null; this.onAnimationLoop = null; +}; + +Phaser.Events.prototype = { + + destroy: function () { + + this.parent = null; + this.onAddedToGroup.dispose(); + this.onRemovedFromGroup.dispose(); + this.onKilled.dispose(); + this.onRevived.dispose(); + this.onOutOfBounds.dispose(); + + if (this.onInputOver) + { + this.onInputOver.dispose(); + this.onInputOut.dispose(); + this.onInputDown.dispose(); + this.onInputUp.dispose(); + this.onDragStart.dispose(); + this.onDragStop.dispose(); + } + + if (this.onAnimationStart) + { + this.onAnimationStart.dispose(); + this.onAnimationComplete.dispose(); + this.onAnimationLoop.dispose(); + } + + } + }; \ No newline at end of file diff --git a/src/gameobjects/Sprite.js b/src/gameobjects/Sprite.js index 58872c37c..1efe45e86 100644 --- a/src/gameobjects/Sprite.js +++ b/src/gameobjects/Sprite.js @@ -580,6 +580,30 @@ Phaser.Sprite.prototype.kill = function() { } +/** +* Description. +* +* @method Phaser.Sprite.prototype.destroy +*/ +Phaser.Sprite.prototype.destroy = function() { + + if (this.group) + { + this.group.remove(this); + } + + this.input.destroy(); + this.events.destroy(); + this.animations.destroy(); + + this.alive = false; + this.exists = false; + this.visible = false; + + this.game = null; + +} + /** * Description. * diff --git a/src/tilemap/TilemapLayer.js b/src/tilemap/TilemapLayer.js index c901ce8a8..75d615f56 100644 --- a/src/tilemap/TilemapLayer.js +++ b/src/tilemap/TilemapLayer.js @@ -197,12 +197,20 @@ Phaser.TilemapLayer.prototype = { return; } + this._prevX = this._dx; + this._prevY = this._dy; + this._dx = -(this._x - (this._startX * this.tileWidth)); this._dy = -(this._y - (this._startY * this.tileHeight)); this._tx = this._dx; this._ty = this._dy; + // First let's just copy over the whole canvas, offset by the scroll difference + + // Then we only need fill in the missing strip/s (could be top/bottom/left/right I guess) + // ScrollZone code might be useful here. + this.context.clearRect(0, 0, this.canvas.width, this.canvas.height); for (var y = this._startY; y < this._startY + this._maxY; y++) @@ -260,11 +268,11 @@ Phaser.TilemapLayer.prototype.deltaAbsY = function () { } Phaser.TilemapLayer.prototype.deltaX = function () { - return this._x - this._prevX; + return this._dx - this._prevX; } Phaser.TilemapLayer.prototype.deltaY = function () { - return this._y - this._prevY; + return this._dy - this._prevY; } Object.defineProperty(Phaser.TilemapLayer.prototype, "x", {