I am very new to Phaser. Here is what I did:
<!DOCTYPE html>
<html>
<body>
<script src="phaser.js"></script>
<script>
var game = new Phaser.Game(500, 500, Phaser.AUTO, '', {
preload : preload,
create : create,
update : update
});
function preload() {
game.load.image('dog', 'assets/dog.png');
}
function create() {
game.stage.backgroundColor = "#1BDCFF";
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.startSystem(Phaser.Physics.ARCADE);
dog = game.add.sprite(game.world.centerX, game.world.centerY, 'dog');
game.physics.arcade.enable(dog);
}
function update() {
}
</script>
</body>
Shouldn't the dog appear in the center of the "world"? Here is how it looks like :
I then tried something like this :
var dogImage = game.cache.getImage('dog');
dog = game.add.sprite(game.world.centerX-dogImage.width/2, game.world.centerY- dogImage.height/2, 'dog');
And now that I edited in this way the create function it does place the dog in the center. Is this the way of doing it or there's a more elegant way ?