Phaser current version test environment
Basic Phaser setup for testing
by Lewis Lane
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.min.js"></script>
<div id="test"></div>
JavaScript
// Phaser current version test environment
// http://codepen.io/netgfx/full/mlIps/ - Particles in Phaser
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
var emitter;
BasicGame.Boot.prototype =
{
preload: function() {
game.stage.backgroundColor = "#cecece";
game.time.advancedTiming = true;
},
create: function()
{
var square = game.make.bitmapData(20, 20);
square.ctx.fillStyle = 'rgb(255,255,255)';
square.ctx.rect(0, 0, 20, 20);
square.ctx.fill();
emitter = game.add.emitter(game.world.centerX, game.world.centerY);
emitter.makeParticles(square);
emitter.setRotation(0, 0);
emitter.setXSpeed(-100, -500);
emitter.setYSpeed(0, -500);
emitter.width = 20;
emitter.height = 30;
emitter.setScale(1, 0, 1, 0, 700, null);
emitter.start(false, 300, 30);
game.time.events.loop(3000, this.changeParticleColor, this);
this.changeParticleColor();
},
update: function()
{
},
render: function()
{
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
game.debug.text(Phaser.VERSION, game.world.width - 55, 14, "#ffff00");
},
changeParticleColor: function() {
var tint = Phaser.ArrayUtils.getRandomItem([0x2ca8c2, 0x98cb4a, 0xf76d3c, 0xf15f74, 0x5481e6]);
emitter.forEach(function(p) {
p.tint = tint;
});
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');