phaser/examples/tile sprites/tiling sprite.js

42 lines
749 B
JavaScript
Raw Normal View History

2013-10-22 02:58:20 +00:00
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
var tilesprite;
var cursors;
2013-10-22 02:58:20 +00:00
function preload() {
2013-10-22 02:58:20 +00:00
game.load.image('starfield', 'assets/misc/starfield.jpg');
2013-10-22 02:58:20 +00:00
}
function create() {
tilesprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
cursors = game.input.keyboard.createCursorKeys();
2013-10-22 02:58:20 +00:00
}
function update() {
if (cursors.left.isDown)
2013-10-22 02:58:20 +00:00
{
tilesprite.tilePosition.x += 8;
2013-10-22 02:58:20 +00:00
}
else if (cursors.right.isDown)
2013-10-22 02:58:20 +00:00
{
tilesprite.tilePosition.x -= 8;
2013-10-22 02:58:20 +00:00
}
if (cursors.up.isDown)
2013-10-22 02:58:20 +00:00
{
tilesprite.tilePosition.y += 8;
2013-10-22 02:58:20 +00:00
}
else if (cursors.down.isDown)
2013-10-22 02:58:20 +00:00
{
tilesprite.tilePosition.y -= 8;
2013-10-22 02:58:20 +00:00
}
}