Phaser 2.0.5 test environment
Basic Phaser setup for testing
by Lewis Lane
HTML
<script src="http://examples.phaser.io/_site/js/phaser.js"></script>
<div id="test"></div>
JavaScript
// Phaser 2.0.5 test environment
// Demonstrating graphics shape positioning around registration
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
this.square = game.add.graphics();
// center the graphics object in the world
this.square.x = game.world.centerX;
this.square.y = game.world.centerY;
this.square.beginFill(0xffffff);
// draw a rectangle at -20, -20 with a width and height of 40, effectively centering it
this.square.drawRect(-20, -20, 40, 40);
},
update: function()
{
this.square.angle++;
// let's make it pulse just because it's a vector, and because we can ;)
this.square.scale.setTo(Math.sin(game.time.now * 0.001) + 2);
},
render: function()
{
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');