Jump to content

Hitbox and Sprite not aligned when group moved? (P2)


Sanic
 Share

Recommended Posts

Maybe I've misunderstood how groups work... I was trying to set up a sprite(paddle) that would collide with the world bounds inside a container(board) that I could move and have the sprite's position be relative to the container. I got the sprite to go where I wanted but the collision rectangle... not so much. The collision works, just it's not where the sprite is...

Here's the relevant code:

this.board = game.add.group();
this.board.paddle = game.add.sprite(0, 0, 'paddle');		
game.physics.p2.enable(this.board.paddle,true);
this.board.add(this.board.paddle);
this.board.paddle.body.setRectangle(64, 16);
this.board.paddle.body.fixedRotation = true;
this.board.paddle.rot = false;
this.board.paddle.prev = 0;
this.board.x = 300;
this.board.y = 100;

In addition, when I rotate in the update with:

this.board.paddle.body.rotateLeft(200);

The sprite and the hitbox both rotate, but don't align after a while.

I'm using Phaser 2.6.1 and with P2 physics started. Can anyone help me keep my sprites and hitboxes aligned?

gamebroken.PNG

offsetgame.PNG

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...