Phaser current version test environment

Basic Phaser setup for testing

by Lewis Lane

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/phaser/2.1.0/phaser.min.js"></script>
<div id="test"></div>

CSS

body {
    background: #333;
}

JavaScript

// Phaser current version test environment
// Group and child positioning

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

var BasicGame = function (game) {};

BasicGame.Boot = function (game) {};

var test = 0, group, shape1, shape2, shape3, shape4, shape5, target;

BasicGame.Boot.prototype = {
    preload: function () {
        
    },
    create: function () {
        // Add a target at the center of the world
        group = game.add.group();
        target = game.add.graphics(game.world.centerX, game.world.centerY);
        target.beginFill(0x00ff00);
        target.drawCircle(0, 0, 8);
        
        // Test 1
        // The red shape should have its top left corner positioned at 0, 0
        shape1 = game.add.sprite(0, 0, this.getPattern(256, 256));
        shape1.tint = 0xff0000;
        group.add(shape1);
        
        // Test 2
        // The yellow and cyan shapes should both have their centers positioned at 0, 0
        shape2 = game.add.sprite(0, 0, this.getPattern(256, 256));
        shape2.anchor.set(0.5);
        shape2.tint = 0xffff00;
        group.add(shape2);
        
        shape3 = game.add.sprite(0, 0, this.getPattern(128, 128));
        shape3.anchor.set(0.5);
        shape3.tint = 0x00ffff;
        group.add(shape3);
        
        // Test 3
        // The magenta shape should have its top left corner positioned at 0, 0 and 
        // the blue shape should have its center positioned at 0, 0
        shape4 = game.add.sprite(0, 0, this.getPattern(256, 256));
        shape4.tint = 0xff00ff;
        group.add(shape4);
        
        shape5 = game.add.sprite(0, 0, this.getPattern(128, 128));
        shape5.anchor.set(0.5);
        shape5.tint = 0x0000ff;
        group.add(shape5);
        
        shape2.visible = shape3.visible = shape4.visible = shape5.visible = false;
        
        game.input.onDown.add(function() {
            test += 1;
            test = test % 3;
            
           ...