2013-10-22 02:58:20 +00:00
|
|
|
|
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
game.load.atlasJSONHash('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json');
|
|
|
|
}
|
|
|
|
|
|
|
|
var s;
|
|
|
|
|
|
|
|
function create() {
|
|
|
|
|
|
|
|
s = game.add.sprite(game.world.centerX, game.world.centerY, 'bot');
|
2014-02-28 18:22:52 +00:00
|
|
|
s.anchor.setTo(0.5, 0.5);
|
2013-10-22 02:58:20 +00:00
|
|
|
s.scale.setTo(2, 2);
|
|
|
|
|
|
|
|
s.animations.add('run');
|
|
|
|
s.animations.play('run', 10, true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
|
|
|
{
|
|
|
|
s.x -= 4;
|
|
|
|
}
|
|
|
|
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
|
|
|
{
|
|
|
|
s.x += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
|
|
|
{
|
|
|
|
s.y -= 4;
|
|
|
|
}
|
|
|
|
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
|
|
|
{
|
|
|
|
s.y += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function render() {
|
2014-03-03 01:19:31 +00:00
|
|
|
game.debug.spriteInfo(s, 20, 32);
|
2013-10-22 02:58:20 +00:00
|
|
|
|
|
|
|
}
|