Phaser current version test environment

Basic Phaser setup for testing

by Lewis Lane

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
<div id="test"></div>

JavaScript

// Phaser current version test environment
// Add duration to timer

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() 
        {
        	// Create a custom timer
					this.countDown = game.time.create(false);
          
          // Set our initial event
          this.countDown.add(Phaser.Timer.SECOND * 10, this.endCountDown, this);
          
          // Start the timer
          this.countDown.start();
          
          // On click, save the current duration, remove all the events then create a new event
          // with the saved duration + 5 seconds
          game.input.onDown.add(function() {
          	var duration = this.countDown.duration;
          	this.countDown.removeAll();
            this.countDown.add(duration + (Phaser.Timer.SECOND * 5), this.endCountDown, this);
            console.log('Added 5 seconds.');
          }, this);
        },
        endCountDown: function() {
        	console.log('Done!');
        },
        update: function() 
        {

            
        }, 
        render: function()
        {
            game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");   
            game.debug.text("Countdown: " + (this.countDown.duration / Phaser.Timer.SECOND), 2, 34, "#ffffff");   
        }
    };

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