Phaser current version 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 current version test environment
// Dynamic button creation with callbacks

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

var BasicGame = function(game) {};

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

var clicked = "No buttons clicked yet.";

BasicGame.Boot.prototype = 
{
    preload: function() {
      game.time.advancedTiming = true;
    },
	create: function() 
	{
        // just a quick texture for the button
        this.button = game.make.graphics();
        this.button.beginFill(0x00ff00);
        this.button.drawCircle(0, 0, 20);
        this.button.cacheAsBitmap = true;
        this.generateButtons();
    },
    update: function() 
    {

    }, 
    render: function()
    {
        game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
        game.debug.text(Phaser.VERSION, game.world.width - 55, 14, "#ffff00");
        game.debug.text(clicked, 180, 120, "#00ff00");
    },
    generateButtons: function() {
      var button;  
      for (var i = 0; i < 6; i++) {    
        button = this.game.add.button(100, 50+i*50, this.button._cachedSprite.texture, this.clickHandler, this, 2, 1, 0);
        button.name = 'button' + i;
      }
    },
    clickHandler: function(button) {
        clicked = 'Clicked ' + button.name + '.';
    }
};

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