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
// Falling, regenerating platforms

var game = new Phaser.Game(600, 400, Phaser.AUTO, 'test');

var BasicGame = function (game) {};

BasicGame.Boot = function (game) {};

var group, player, platform1, platform2;

BasicGame.Boot.prototype = {
  preload: function () {
    game.time.advancedTiming = true;
  },
  create: function () {
    var bmd = game.add.bitmapData(32, 32);
    bmd.ctx.rect(0, 0, 32, 32);
    bmd.ctx.fillStyle = "#0f0";
    bmd.ctx.fill();
    
    // how much we want to 'jiggle' by
    this.jiggleAmount = 50;

    // example 1: 'jiggle' left and right with a tween
    this.jiggle1 = game.add.sprite(game.world.centerX - this.jiggleAmount, game.world.centerY - 36, bmd);
    this.jiggle1.anchor.set(0.5);

    game.add.tween(this.jiggle1).to({
      x: game.world.centerX + this.jiggleAmount
    }, 100, Phaser.Easing.Linear.None, true, 0, Infinity, true);

    // example 2: 'jiggle' the position instantly by random amounts
    this.jiggle2 = game.add.sprite(game.world.centerX - this.jiggleAmount, game.world.centerY, bmd);
    this.jiggle2.anchor.set(0.5);
    // continued in update function...

    // example 3: 'jiggle' the position via a tween by random amounts
    this.jiggle3 = game.add.sprite(game.world.centerX, game.world.centerY + 36, bmd);
    this.jiggle3.anchor.set(0.5);

		var self = this;
		function jiggle3() {
      var jiggle3Tween = game.add.tween(self.jiggle3).to({
        x: game.world.centerX + game.rnd.integerInRange(-self.jiggleAmount, self.jiggleAmount)
      }, 100, Phaser.Easing.Quadratic.InOut, true);
      
      jiggle3Tween.onComplete.add(jiggle3, self);
    }
    
    jiggle3();
  },
  update: function () {
  	// update the x position of the second square each frame
    this.jiggle2.x = game.world.centerX + game.rnd.integerInRange(-this.jiggleAmount, this.jiggleAmount);
  },
  render: function () {
    game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
 ...