Phaser current version test environment
Basic Phaser setup for testing
by Lewis Lane
HTML
<script src="//rawgit.com/photonstorm/phaser/master/build/phaser.min.js"></script>
<div id="test"></div>
CSS
body {
background: #333;
}
JavaScript
// Phaser current version test environment
// Triggered trap example
var game = new Phaser.Game(400, 100, Phaser.AUTO, 'test', null, false, false);
var BasicGame = function (game) {};
BasicGame.Boot = function (game) {};
BasicGame.Boot.prototype = {
preload: function () {
},
create: function () {
// Create our group for the traps
this.trapGroup = game.add.group();
this.trapGroup.enableBody = true;
// Create our group for the triggers
this.triggerGroup = game.add.group();
this.triggerGroup.enableBody = true;
// Start some gravity
game.physics.arcade.gravity.y = 500;
// Create a green circle for our player
var playerBmd = game.add.bitmapData(32, 32);
playerBmd.circle(16, 16, 16, '#0f0');
// Add our player sprite and set up the physics
this.player = game.add.sprite(0, 0, playerBmd);
game.physics.arcade.enable(this.player);
this.player.body.collideWorldBounds = true;
// Create a red square for the trap
var trapBmd = game.add.bitmapData(32, 32);
trapBmd.rect(0, 0, 32, 32, '#f00');
// Create an instance of our Trap object, extended from Phaser.Sprite - the last parameter
// tells the trap where to put the trigger it creates itself.
this.trap = new Trap(game, 100, 0, trapBmd, 0, this.triggerGroup);
// Add the trap to the trap group
this.trapGroup.add(this.trap);
// Just set some cursor keys up so we can move our player
this.cursors = game.input.keyboard.createCursorKeys();
},
update: function () {
// Our player movement routine, really simple...
var speed = 100;
if (this.cursors.left.isDown) {
this.player.body.velocity.x = speed * -1;
}
else if (this.cursors.right.isDown) {
this.player.body.velocity.x =...