2014-02-13 15:04:01 +00:00
|
|
|
|
2014-02-13 23:13:10 +00:00
|
|
|
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render });
|
2014-02-13 15:04:01 +00:00
|
|
|
|
|
|
|
var tilesprite;
|
|
|
|
var cursors;
|
|
|
|
|
|
|
|
function preload() {
|
|
|
|
|
|
|
|
game.load.image('starfield', 'assets/misc/starfield.jpg');
|
2014-02-13 23:13:10 +00:00
|
|
|
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');
|
2014-02-13 15:04:01 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-13 23:13:10 +00:00
|
|
|
var sprite;
|
|
|
|
|
2014-02-13 15:04:01 +00:00
|
|
|
function create() {
|
|
|
|
|
2014-02-13 23:13:10 +00:00
|
|
|
// 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');
|
2014-02-13 15:04:01 +00:00
|
|
|
|
2014-02-13 23:13:10 +00:00
|
|
|
sprite.animations.play('walk', 20, true);
|
2014-02-13 15:04:01 +00:00
|
|
|
|
|
|
|
cursors = game.input.keyboard.createCursorKeys();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function update() {
|
|
|
|
|
|
|
|
if (cursors.left.isDown)
|
|
|
|
{
|
2014-02-13 23:13:10 +00:00
|
|
|
sprite.tilePosition.x += 8;
|
|
|
|
sprite.x -= 4;
|
2014-02-13 15:04:01 +00:00
|
|
|
}
|
|
|
|
else if (cursors.right.isDown)
|
|
|
|
{
|
2014-02-13 23:13:10 +00:00
|
|
|
sprite.tilePosition.x -= 8;
|
|
|
|
sprite.x += 4;
|
2014-02-13 15:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cursors.up.isDown)
|
|
|
|
{
|
2014-02-13 23:13:10 +00:00
|
|
|
sprite.tilePosition.y += 8;
|
2014-02-13 15:04:01 +00:00
|
|
|
}
|
|
|
|
else if (cursors.down.isDown)
|
|
|
|
{
|
2014-02-13 23:13:10 +00:00
|
|
|
sprite.tilePosition.y -= 8;
|
2014-02-13 15:04:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-02-13 23:13:10 +00:00
|
|
|
|
|
|
|
function render() {
|
|
|
|
|
|
|
|
game.debug.renderText(sprite.frame, 32, 32);
|
|
|
|
|
|
|
|
}
|