Phaser updown test p2 worldgroup
phaser tests
HTML
<script src="http://examples.phaser.io/_site/js/phaser.js"></script>
JavaScript
function State() {}
State.prototype = {
preload: function () {
game.load.image('backdrop', 'http://www.thinksnaps.com/wp-content/uploads/2014/07/152-black-background-metal-hole-wallpaper.jpg');
game.load.image('player', 'per.jpg');
},
create: function() {
this.game.world.setBounds(-2048,-2048,4096, 4096);
this.worldgroup = this.game.add.group();
this.backdrop = this.game.add.sprite(0,0,'backdrop');
this.worldgroup.add(this.backdrop);
this.player = this.game.add.sprite(1024,1024,'player');
this.player.anchor.setTo(.5,.5);
this.worldgroup.add(this.player);
cursors = this.game.input.keyboard.createCursorKeys();
},
update: function() {
if (cursors.left.isDown)
{
if (cursors.left.shiftKey) {
this.player.rotation -= 0.05;
this.worldgroup.rotation = -1*this.player.rotation;
} else {
this.player.x -= 4 * Math.cos(this.player.rotation);
this.player.y -= 4 * Math.sin(this.player.rotation);
}
}
else if (cursors.right.isDown)
{
if (cursors.right.shiftKey) {
this.player.rotation += 0.05;
this.worldgroup.rotation = -1*this.player.rotation;
} else {
this.player.x += 4 * Math.cos(this.player.rotation);
this.player.y += 4 * Math.sin(this.player.rotation);
}
}
if (cursors.up.isDown)
{
this.player.y -= 4*Math.cos(this.player.rotation);
this.player.x += 4*Math.sin(this.player.rotation);
}
else if (cursors.down.isDown)
{
this.player.y += 4*Math.cos(this.player.rotation);
this.player.x -= 4*Math.sin(this.player.rotation);
}
this.worldgroup.pivot.x = this.player.x;
this.worldgroup.pivot.y = this.player.y;
this.worldgroup.x =...