Phaser current version test environment

Basic Phaser setup for testing

by Lewis Lane

HTML

<script src="https://rawgit.com/photonstorm/phaser/master/build/phaser.min.js"></script>
<div id="test"></div>

JavaScript

// Phaser current version test environment
// Circular motion with physics

var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');

var BasicGame = function(game) {};

BasicGame.Boot = function (game) {
    // nothing here
};

var square, period = 0;

BasicGame.Boot.prototype = 
{
    preload: function() {
      game.time.advancedTiming = true;
    },
	create: function() 
	{
        var squarebmp = game.add.bitmapData(32, 32);
        
        squarebmp.ctx.rect(0, 0, 32, 32);
        squarebmp.ctx.fillStyle = "#fff";
        squarebmp.ctx.fill();
       
        square = game.add.sprite(game.world.centerX, game.world.centerY, squarebmp);
        square.anchor.set(0.5);
        
        game.physics.enable(square, Phaser.Physics.ARCADE);
        
    },
    update: function() {
        period += 0.05;
        var multiplier = 50;
        square.body.velocity.x = Math.cos(period) * multiplier;
        square.body.velocity.y = Math.sin(period) * multiplier;
    },
    render: function()
    {
        game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");   
    }
};

game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');