phaser/wip/TS Tests/sprites/animate by framename.ts

43 lines
960 B
TypeScript
Raw Normal View History

2013-07-13 11:38:59 +00:00
/// <reference path="../../Phaser/Game.ts" />
(function () {
var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update);
2013-07-13 11:38:59 +00:00
function preload() {
2013-07-13 11:38:59 +00:00
2013-08-02 17:32:26 +00:00
game.load.atlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
2013-07-13 11:38:59 +00:00
2013-07-13 11:38:59 +00:00
}
var bot: Phaser.Sprite;
function create() {
2013-08-02 17:32:26 +00:00
bot = game.add.sprite(game.stage.width, 300, 'bot');
2013-07-13 11:38:59 +00:00
// If you are using a Texture Atlas and want to specify the frames of an animation by their name rather than frame index
// then you can use this format:
bot.animations.add('run', ['run00', 'run01', 'run02', 'run03', 'run04', 'run05', 'run06', 'run07', 'run08', 'run09', 'run10'], 10, true, false);
bot.animations.play('run');
2013-08-02 17:32:26 +00:00
//bot.velocity.x = -100;
2013-07-13 11:38:59 +00:00
}
function update() {
2013-08-02 17:32:26 +00:00
bot.x -= 1;
2013-07-13 11:38:59 +00:00
if (bot.x < -bot.width)
{
2013-08-02 17:32:26 +00:00
bot.x = game.stage.width;
2013-07-13 11:38:59 +00:00
}
}
})();