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
// Pushable, stackable objects
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
// generate a background
var checkerboard = game.add.bitmapData(64, 64);
checkerboard.ctx.fillStyle = 'rgb(40,40,40)';
checkerboard.ctx.fillRect(0, 0, 32, 32);
checkerboard.ctx.fillRect(32, 32, 32, 32);
var bg = game.add.tileSprite(0, 0, game.world.width, game.world.height, checkerboard);
// add our player
this.square = game.add.sprite(game.world.centerX, game.world.centerY);
this.square.speed = 100;
var squareGraphics = game.add.graphics();
squareGraphics.beginFill(0xffffff);
squareGraphics.drawCircle(0, 0, 16);
this.square.addChild(squareGraphics);
this.game.physics.enable(this.square, Phaser.Physics.ARCADE);
this.square.body.gravity.y = 600;
this.square.body.setSize(32, 32, -16, -16);
this.square.budge = 0;
this.square.body.collideWorldBounds = true;
this.cursors = game.input.keyboard.createCursorKeys();
// create something for the action to happen on top of (oo-er!)
this.ground = game.add.sprite(0, game.world.height - 32);
var groundGraphics = game.add.graphics();
groundGraphics.beginFill(0x999999);
groundGraphics.drawRect(0, 0, game.world.width, 32);
this.ground.addChild(groundGraphics);
game.physics.enable(this.ground, Phaser.Physics.ARCADE);
this.ground.body.immovable = true;
this.ground.body.setSize(game.world.width, 32, 0, 0);
// set up our 'crates'
this.crates = game.add.group();
this.crates.enableBody =...