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
// Extending a Sprite and checking for animation properties
// BUCKS FIZZ EDITION! MERRY CHRISTMAS!!
var game = new Phaser.Game(600, 400, Phaser.AUTO, 'test');
var BasicGame = function (game) {};
BasicGame.Boot = function (game) {};
BasicGame.Boot.prototype = {
preload: function () {
// game.time.advancedTiming = true;
// Just a quick base64 encoded animation
game.load.spritesheet('bubble', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAIAQMAAACiS2/sAAAABlBMVEUAAAD///+l2Z/dAAAAAXRSTlMAQObYZgAAAB9JREFUCNdjAAIBIJZwAGIVJiB2YgATILIBRDKBlQAAMM4Cid0EWS0AAAAASUVORK5CYII=', 8, 8);
game.stage.backgroundColor = '#f90';
},
create: function () {
// Create 256 extended sprites at random locations with the bubble spritesheet
for (var i = 0; i < 256; i++) {
game.add.existing(new ExtendedSprite(game, game.world.randomX, game.world.randomY, 'bubble'));
}
},
render: function () {
// game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
},
};
var ExtendedSprite = function (game, x, y, key, frame) {
// Call the super constructor to set the sprite up
Phaser.Sprite.call(this, game, x, y, key, frame);
// Center the sprite's origin
this.anchor.set(0.5);
// Pick a random cardinal direction and flip the sprite randomly in either or both directions
this.angle = 90 * game.rnd.integerInRange(0,3);
this.scale.x = game.rnd.pick([-1,1]);
this.scale.y = game.rnd.pick([-1,1]);
// Set a random speed for this bubble to rise at
this.riseSpeed = 0.5 * game.rnd.integerInRange(1,4);
// Add the anim
this.animations.add('bubble', [0, 1, 2, 3]);
// Play the anim at a random framerate between 5 and 10
this.animations.play('bubble', game.rnd.integerInRange(5, 10), true);
};
ExtendedSprite.prototype =...