phaser/wip/phaser tests/collision/mask animation 1.ts
2013-09-13 16:24:01 +01:00

50 lines
1.1 KiB
TypeScript

/// <reference path="../../Phaser/Game.ts" />
(function () {
var myGame = new Phaser.Game(this, 'game', 800, 600, init, create, update);
function init() {
myGame.loader.addImageFile('card', 'assets/sprites/mana_card.png');
myGame.loader.addTextureAtlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
myGame.loader.load();
}
var card: Phaser.Sprite;
var bot: Phaser.Sprite;
function create() {
card = myGame.add.sprite(200, 220, 'card');
bot = myGame.add.sprite(myGame.stage.width - 100, 300, 'bot');
// The collision mask is much thinner than the animated sprite
bot.collisionMask.offset.x = 16;
bot.collisionMask.width = 32;
bot.renderDebug = true;
bot.animations.add('run');
bot.animations.play('run', 10, true);
bot.velocity.x = -150;
}
function update() {
if (bot.x < -bot.width)
{
bot.x = myGame.stage.width;
bot.velocity.x = -150;
card.x = 200;
card.velocity.x = 0;
}
myGame.collide(card, bot);
}
})();