Phaser current version test environment
Basic Phaser setup for testing
by Lewis Lane
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
<div id="test"></div>
JavaScript
// Phaser current version test environment
// Smoothed camera with parallax scrolling and targeting
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
var cameraPos = new Phaser.Point(0, 0), target;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
// generate a background so we can see the world/camera movement
var checkerboard = game.add.bitmapData(64, 64);
checkerboard.ctx.fillStyle = 'rgb(255,255,255)';
checkerboard.ctx.fillRect(0, 0, 32, 32);
checkerboard.ctx.fillRect(32, 32, 32, 32);
this.bg = game.add.tileSprite(0, 0, game.width, game.height, checkerboard);
this.bg.fixedToCamera = true;
this.bg.tileScale.set(0.5);
this.bg.tint = 0x660000;
this.bgnear = game.add.tileSprite(0, 0, game.width, game.height, checkerboard);
this.bgnear.fixedToCamera = true;
this.bgnear.tint = 0xcc4400;
this.square = game.add.group();
this.square.speed = 5;
var squareGraphics = game.add.graphics();
squareGraphics.beginFill(0xffffff);
squareGraphics.drawCircle(0, 0, 16);
this.square.add(squareGraphics);
this.cursors = game.input.keyboard.createCursorKeys();
this.game.world.setBounds(-512, -512, 1024, 1024);
target = this.square;
this.game.input.onDown.add(function() {
target = (target ? null : this.square);
}, this);
},
update: function()
{
if (this.cursors.left.isDown) {
this.square.x -= this.square.speed;
}
else if...