Skip to content

Instantly share code, notes, and snippets.

@noidexe
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noidexe/8d472a5e51fac1440130 to your computer and use it in GitHub Desktop.
Save noidexe/8d472a5e51fac1440130 to your computer and use it in GitHub Desktop.
Movable Tile
MovableTile.prototype.postTileAnimation = function () {
//mover el sprite a donde no se vea
this.x = -100;
this.y = -100;
//restaurar el tile
_tile.map.putTile(_tile.index, _tile.x, _tile.y)
};
MovableTile.prototype.doTileAnimation = function () {
//Aca va todo el codigo que maneje la animacion del sprite segun lo que quieras hacer
//en alguna parte tiene que llamar a this.postTileAnimation(); cuando la animacion finaliza
};
var MovableTile = function (game, image, tile, map) {
Phaser.Sprite.call(this, game, tile.worldX, tile.worldY, image, tile.index - 1);
this._tile = {};
this._tile.map = map;
this._tile.x = tile.x;
this._tile.y = tile.y;
this._tile.index = tile.index;
this._game = game;
map.removeTile(tile.x, tile.y);
game.add.existing(this);
game.physics.enable(this, Phaser.Physics.ARCADE);
this.body.immovable = true;
};
MovableTile.prototype = Object.create(Phaser.Sprite.prototype);
MovableTile.prototype.constructor = MovableTile;
MovableTile.prototype.restartTile = function () {
this.x = -100;
this.y = -100;
this._tile.map.putTile(this._tile.index, this._tile.x, this._tile.y)
};
MovableTile.prototype.animateTile = function () {
var self = this;
this._game.add.tween(this).to( { y: this._game.height + 32 }, 2400, Phaser.Easing.Linear.None).start().onComplete.add(function(){
self.restartTile();
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment