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
// Procedurally draw a box

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

var BasicGame = function(game) {};

BasicGame.Boot = function (game) {
    // nothing here
};

var bmd, queue = [];

BasicGame.Boot.prototype = 
{
    preload: function() {
      game.time.advancedTiming = true;
    },
	create: function() 
	{
        // Create our bitmapData and apply it to a Sprite
        bmd = game.add.bitmapData(400, 400);
        game.add.sprite(40, 40, bmd);
        
        // Feed the drawShape function an array of points
        this.drawShape([
            new Phaser.Point(5, 5),
            new Phaser.Point(275, 20),
            new Phaser.Point(245, 265),
            new Phaser.Point(25, 275)
        ]);
    },
    update: function() {
        
    },
    render: function()
    {
        game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");   
    },
    drawShape: function(pts) {
        var p;

        // Loop through all of the points and add 'plot' commands
        for (p = 0; p < pts.length; p++) {
            queue.push({action: "plot", pt: pts[p]});   
        }
        
        // Move back to the first point
        queue.push({action: "move", pt: pts[0]});
        
        // Shift the array so the last point is the first, so we make a complete square with the lines that follow
        Phaser.Math.shift(pts);
        
        // Loop through the shifted points and add 'line' commands
        for (p = 0; p < pts.length; p++) {
            queue.push({action: "line", pt: pts[p]});   
        }

        // Begin processing the queue of commands we've created
        this.processQueue();
    },
    processQueue: function() {
        // Are there any commands left to process?
        if (queue.length == 0) {
            return;
        }
        
        // Get the next command from the front of the queue
        var a = queue.shift();
        
        // Parse our commands and perform the...