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
// Custom timer with extension
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
// initialise up our endTime var
var endTime = 0;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
// set the end time to 30 seconds in the future
endTime = game.time.now + (1000 * 10);
// every time the user clicks, add 5 seconds to the end time
game.input.onDown.add(function() {
endTime = endTime + (1000 * 5);
console.log("Added 5 seconds");
}, this);
},
update: function()
{
},
render: function()
{
// get time remaining in miliseconds
var timeLeft = endTime - game.time.now;
if (timeLeft >= 0) {
// show time remaining in seconds (divide by 1000)
game.debug.text(Math.ceil(timeLeft / 1000) + " seconds left!", 100, 100, "#00ff00");
}
else {
game.debug.text("Ran out of time!", 100, 100, "#ff0000");
}
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
game.debug.text(Phaser.VERSION, game.world.width - 55, 14, "#ffff00");
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');