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
// One Armed Bandit via TileSprite test
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
// initialise up our endTime var
var endTime = 0;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
// just generate a basic texture so we don't have to load anything
var symbols = game.make.graphics();
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0x00ffff, 0xff00ff, 0xffff00, 0xffffff, 0x666666];
for (var i = 0; i < 8; i++) {
symbols.beginFill(colors[i]);
symbols.drawRect(0, i*32, 128, 32);
}
symbols.boundsPadding = 0;
symbols.cacheAsBitmap = true;
// create our TileSprite reel using the texture from above
var reel = game.add.tileSprite(game.world.centerX, game.world.centerY - 20, 128, 300, symbols._cachedSprite.texture);
reel.anchor.set(0.5);
// add a tween to the tilePosition on input down
game.input.onDown.add(function() {
var spin = Math.random() * 3;
game.add.tween(reel.tilePosition).to({y: spin * 1000}, (spin * 1000) + 5000, Phaser.Easing.Quadratic.Out, true);
}, this);
},
update: function()
{
},
render: function()
{
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
game.debug.text(Phaser.VERSION, game.world.width - 55, 14, "#ffff00");
game.debug.text("Click/tap to spin the wheel", 120, 360);
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');