Phaser updown test p2 worldgroup

phaser tests

by luckylooke

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() {
      game.physics.startSystem(Phaser.Physics.P2JS);
        
      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);
        
      game.physics.p2.enable([this.player]);


      cursors = this.game.input.keyboard.createCursorKeys();
    },
    update: function() {


        if (cursors.left.isDown)
        {
              this.player.body.rotation -= 0.05;
            this.worldgroup.rotation = -1*this.player.rotation;
        }
        else if (cursors.right.isDown)
        {
              this.player.body.rotation += 0.05;
            this.worldgroup.rotation = -1*this.player.rotation;
        }

        if (cursors.up.isDown)
        {
            this.player.body.thrust(300);
        }
        else if (cursors.down.isDown)
        {
            this.player.body.reverse(100);
        }
        this.worldgroup.pivot.x = this.player.x;
        this.worldgroup.pivot.y = this.player.y;
        this.worldgroup.x = this.worldgroup.pivot.x;
        this.worldgroup.y = this.worldgroup.pivot.y;
        this.game.camera.focusOnXY(this.player.x, this.player.y + this.player.height - this.camera.view.halfHeight);
    }
  };

var game = new Phaser.Game(
440,
600,
Phaser.CANVAS,
    'game',
State);