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
// Getting a point by distance in a direction
var game = new Phaser.Game(500, 400, Phaser.AUTO, 'test');
var BasicGame = function(game) {};
BasicGame.Boot = function (game) {
// nothing here
};
var cameraPos = new Phaser.Point(0, 0);
// the length of our barrel - try changing this to see that it updates appropriately
var barrelLength = 40;
BasicGame.Boot.prototype =
{
preload: function() {
game.time.advancedTiming = true;
},
create: function()
{
this.gun = game.add.graphics();
this.gun.beginFill(0xffffff);
this.gun.drawCircle(0, 0, 20);
this.gun.drawRect(0, -10, barrelLength, 20);
this.gun.position.setTo(game.world.centerX, game.world.centerY);
this.muzzle = game.add.graphics();
this.muzzle.lineStyle(2, 0xff0000);
this.muzzle.moveTo(0, -10);
this.muzzle.lineTo(0, 10);
this.muzzle.moveTo(10, 0);
this.muzzle.lineTo(-10, 0);
this.muzzle.position.setTo(game.world.centerX, game.world.centerY);
},
update: function()
{
this.gun.angle++;
// place the muzzle position to the gun position projected out by the length of the barrel in the direction the gun's facing
this.muzzle.x = this.gun.x + (Math.cos(this.gun.rotation) * barrelLength);
this.muzzle.y = this.gun.y + (Math.sin(this.gun.rotation) * barrelLength);
},
render: function()
{
game.debug.text(game.time.fps || '--', 2, 14, "#00ff00");
},
fireBullet: function() {
}
};
game.state.add('Boot', BasicGame.Boot);
game.state.start('Boot');