mirror of
https://github.com/photonstorm/phaser
synced 2024-11-22 12:43:26 +00:00
34 lines
739 B
JavaScript
34 lines
739 B
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
|
|
|
|
var s;
|
|
|
|
function preload() {
|
|
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
|
}
|
|
|
|
function create() {
|
|
s = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT))
|
|
{
|
|
s.tilePosition.x += 8;
|
|
}
|
|
else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT))
|
|
{
|
|
s.tilePosition.x -= 8;
|
|
}
|
|
|
|
if (game.input.keyboard.isDown(Phaser.Keyboard.UP))
|
|
{
|
|
s.tilePosition.y += 8;
|
|
}
|
|
else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN))
|
|
{
|
|
s.tilePosition.y -= 8;
|
|
}
|
|
|
|
}
|