phaser/examples/wip/tilesprite.js

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2014-02-13 15:04:01 +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');
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
}
var sprite;
2014-02-13 15:04:01 +00:00
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');
2014-02-13 15:04:01 +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)
{
sprite.tilePosition.x += 8;
sprite.x -= 4;
2014-02-13 15:04:01 +00:00
}
else if (cursors.right.isDown)
{
sprite.tilePosition.x -= 8;
sprite.x += 4;
2014-02-13 15:04:01 +00:00
}
if (cursors.up.isDown)
{
sprite.tilePosition.y += 8;
2014-02-13 15:04:01 +00:00
}
else if (cursors.down.isDown)
{
sprite.tilePosition.y -= 8;
2014-02-13 15:04:01 +00:00
}
}
function render() {
game.debug.renderText(sprite.frame, 32, 32);
}