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
// Removing tweens - click inside the canvas then press space to stop the tween

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() 
	{
        var ball = game.add.graphics();
        ball.beginFill(0xffffff);
        ball.drawCircle(20, 20, 20);
        
        this.idleBallTween = this.game.add.tween(ball).to({y: 50}, 500 , Phaser.Easing.Sinusoidal.InOut, true, 0, 9999, true);
    },
    update: function() 
    {
        if (this.game.input.keyboard.justPressed(Phaser.Keyboard.SPACEBAR)) {
          game.tweens.remove(this.idleBallTween);   
        }
    }, 
    render: function()
    {
        game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");   
        game.debug.text("Tween running: " + !this.idleBallTween.pendingDelete, 2, 110);
    }
};

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