Phaser 2.0.4 test environment
Basic Phaser setup for testing
by Lewis Lane
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.0.4/phaser.min.js"></script>
<div id="test"></div>
JavaScript
// Phaser 2.0.4 test environment
// Continual adjustment of velocity on input hold
var preload = function(game) {
game.time.advancedTiming = true;
}
var create = function(game) {
// just some boilerplate to get a sprite on the screen without assets
this.bird = game.add.sprite(game.world.centerX - 20, 0, null);
var birdGraphic = game.add.graphics();
birdGraphic.beginFill(0xffffff);
birdGraphic.drawCircle(20, 20, 20);
this.bird.addChild(birdGraphic);
game.physics.arcade.enable(this.bird);
this.bird.body.setSize(40, 40);
// ensure the 'bird' doesn't fall off the bottom of the screen
this.bird.body.collideWorldBounds = true;
// set our gravity
game.physics.arcade.gravity.setTo(0, 1000);
// set a maximum velocity for our 'smooth' method
this.bird.body.maxVelocity.setTo(500, 1000)
}
var update = function(game) {
if (game.input.activePointer.isDown) {
// smoothly increase the upward velocity to simulate flying
this.bird.body.velocity.y += -50;
// alternatively just set the velocity for a sharper jump upwards
// though this will probably not be the way you want to do it
// this.bird.body.velocity.y = -200;
}
}
var render = function(game) {
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
}
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test', { preload: preload, create: create, update: update, render: render });