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
// Jump and spin
var game = new Phaser.Game(600, 400, Phaser.AUTO, 'test');
var BasicGame = function (game) {};
var player, jumpLength = 600, jumpHeight = 100;
BasicGame.Boot = function (game) {};
BasicGame.Boot.prototype = {
preload: function () {
game.time.advancedTiming = true;
},
create: function () {
var bmp = game.add.bitmapData(32, 32);
bmp.rect(0, 0, 32, 32, '#fff');
player = game.add.sprite(game.world.centerX, game.world.centerY, bmp);
player.anchor.set(0.5);
game.input.onDown.add(this.jump, this);
},
render: function () {
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
game.debug.text("Click/tap to jump", 215, 300, "#ffffff");
},
jump: function() {
// Cancel if already jumping
if (player.jumping) {
return;
}
// Reset the angle
player.angle = 0;
// Set the jumping flag
player.jumping = true;
// Do the 'jump' tweens
game.add.tween(player)
.to({y: game.world.centerY - jumpHeight}, jumpLength * 0.5, Phaser.Easing.Quadratic.Out)
.to({y: game.world.centerY}, jumpLength * 0.5, Phaser.Easing.Quadratic.In).start();
// Do the 'spin' tween, and reset the jumping flag when done
game.add.tween(player)
.to({angle: 360}, jumpLength, Phaser.Easing.Linear.None, true)
.onComplete.add(function() {
player.jumping = false;
}, this);
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');