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
// Using groups and tweens to create multiplexed motion
var game = new Phaser.Game(600, 400, Phaser.AUTO, 'test', null, false, false);
var BasicGame = function (game) {};
BasicGame.Boot = function (game) {};
var group;
BasicGame.Boot.prototype = {
preload: function () {
},
create: function () {
group = game.add.group();
group.position.set(game.world.centerX, game.world.centerY);
var tag = game.add.sprite(0, 0, this.getPattern(64, 128), 0, group);
// Set our tween
game.add.tween(tag).to({angle: 20}, 1000, Phaser.Easing.Sinusoidal.InOut, true, 0, Infinity, true);
},
update: function () {
// Increase the angle of the group just to show how the tween still works independent of group angle
group.angle += 0.1;
},
render: function () {
},
getPattern: function(width, height) {
var size = 32, half = size * 0.5, bmd = game.add.bitmapData(width, height);
bmd.rect(0, 0, width, height, '#666');
for (var x = 0; x <= width; x += size) {
for (var y = 0; y <= height; y += size) {
bmd.rect(x, y, half, half, '#ddd');
bmd.rect(x + half, y + half, half, half, '#ddd');
}
}
return bmd;
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');