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
// Scrolling a background at a consistent speed
var game = new Phaser.Game(500, 400, Phaser.CANVAS, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
var emitter;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
game.load.image('background', 'http://www.html5gamedevs.com/uploads/monthly_07_2014/post-9920-0-31199100-1406793393.png');
game.stage.backgroundColor = '#ffffff';
},
create: function()
{
this.background = game.add.tileSprite(0, game.height - 239, game.width, 239, 'background');
},
update: function()
{
// speed to scroll in pixels per second
var scrollSpeed = 50;
// a little bit of math to make sure the speed is consistent whatever the fps
this.background.tilePosition.x -= scrollSpeed * (game.time.elapsed * 0.001);
},
render: function()
{
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');