mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 08:31:01 +00:00
61 lines
1.3 KiB
JavaScript
61 lines
1.3 KiB
JavaScript
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
|
|
|
var tilesprite;
|
|
var cursors;
|
|
|
|
function preload() {
|
|
|
|
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
|
game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18);
|
|
game.load.atlas('seacreatures', 'assets/sprites/seacreatures_json.png', 'assets/sprites/seacreatures_json.json');
|
|
|
|
}
|
|
|
|
var sprite;
|
|
|
|
function create() {
|
|
|
|
// sprite = game.add.tileSprite(0, 0, 800, 600, 'starfield');
|
|
|
|
// sprite = game.add.tileSprite(100, 100, 400, 300, 'starfield');
|
|
|
|
sprite = game.add.tileSprite(100, 100, 400, 300, 'mummy');
|
|
|
|
sprite.animations.add('walk');
|
|
|
|
sprite.animations.play('walk', 20, true);
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
}
|
|
|
|
function update() {
|
|
|
|
if (cursors.left.isDown)
|
|
{
|
|
sprite.tilePosition.x += 8;
|
|
sprite.x -= 4;
|
|
}
|
|
else if (cursors.right.isDown)
|
|
{
|
|
sprite.tilePosition.x -= 8;
|
|
sprite.x += 4;
|
|
}
|
|
|
|
if (cursors.up.isDown)
|
|
{
|
|
sprite.tilePosition.y += 8;
|
|
}
|
|
else if (cursors.down.isDown)
|
|
{
|
|
sprite.tilePosition.y -= 8;
|
|
}
|
|
|
|
}
|
|
|
|
function render() {
|
|
|
|
game.debug.text(sprite.frame, 32, 32);
|
|
|
|
}
|