mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 08:31:01 +00:00
48 lines
1,013 B
JavaScript
48 lines
1,013 B
JavaScript
|
|
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');
|
|
// s.anchor.setTo(0.5, 0.5);
|
|
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() {
|
|
|
|
game.debug.renderSpriteCorners(s, false, false);
|
|
game.debug.renderSpriteInfo(s, 20, 32);
|
|
|
|
}
|