phaser/examples/tile sprites/tiling sprite.js
2013-10-22 03:58:20 +01:00

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;
}
}