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
// Riding object oriented 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() 
	{
        game.physics.arcade.gravity.setTo(0, 900);
        group = game.add.group();
        group.enableBody = true;
        
        var playerbmd = game.add.bitmapData(32, 32);
        playerbmd.ctx.rect(0, 0, 32, 32);
        playerbmd.ctx.fillStyle = "#0f0";
        playerbmd.ctx.fill();
        
        var platformbmd = game.add.bitmapData(80, 16);
        platformbmd.ctx.rect(0, 0, 80, 16);
        platformbmd.ctx.fillStyle = "#fff";
        platformbmd.ctx.fill();        
        
        player = game.add.sprite(game.world.centerX, game.world.centerY, playerbmd);
        game.physics.arcade.enable(player);
        player.anchor.set(0.5);
        player.body.collideWorldBounds = true;
        
        var platform1 = new Platform(game, game.world.centerX, game.world.centerY + 50, platformbmd, 0, Platform.HORIZONTAL, -200, 200, 100);
        group.add(platform1);
        
        var platform2 = new Platform(game, game.world.centerX + 50, game.world.centerY, platformbmd, 0, Platform.VERTICAL, -100, 100, -200);
        group.add(platform2);
        
        // Important - the platforms need to move via velocity, not via direct moving (tweens etc) otherwise they will not allow the player to 'ride' them

        
        this.cursors = game.input.keyboard.createCursorKeys();
        
    },
    update: function() {
        var self = this;
        
        player.body.velocity.x = 0;
        
        if (this.cursors.left.isDown) {
            player.body.velocity.x = -150;   
        }
        else if (this.cursors.right.isDown) {
            player.body.velocity.x = 150;   
       ...