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
// Decelerate to pointer
var game = new Phaser.Game(600, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {};
var circleSprite;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
var circle = game.add.bitmapData(32, 32);
circle.ctx.fillStyle = "#0f0";
circle.ctx.arc(16, 16, 16, 0, 2 * Math.PI, false);
circle.ctx.fill();
circleSprite = game.add.sprite(game.world.centerX, game.world.centerY, circle);
circleSprite.anchor.set(0.5);
game.physics.arcade.enable(circleSprite);
},
update: function() {
if (game.input.activePointer.isDown)
{
game.physics.arcade.moveToPointer(circleSprite, 250, game.input.activePointer, 500);
}
else {
game.physics.arcade.moveToXY(circleSprite, game.world.centerX, game.world.centerY, 250, 200);
}
},
render: function()
{
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
}
};
var SpeechBubble = function(game, x, y, width, text) {
Phaser.Sprite.call(this, game, x, y);
// Some sensible minimum defaults
width = width || 27;
var height = 18;
// Set up our text and run our custom wrapping routine on it
this.bitmapText = game.make.bitmapText(x + 12, y + 4, '8bitoperator', text, 22);
SpeechBubble.wrapBitmapText(this.bitmapText, width);
// Calculate the width and height needed for the edges
var bounds = this.bitmapText.getLocalBounds();
if (bounds.width + 18 > width) {
width = bounds.width + 18;
}
if (bounds.height + 14 > height) {
height = bounds.height + 14;
}
// Create all of our corners and edges
this.borders = [
game.make.tileSprite(x + 9, y + 9, width - 9, height - 9, 'bubble-border', 4),
...