Jump to content

p2 physics hittest on mouse click never works


amkazan
 Share

Recommended Posts

Hello!

Does anybody know what could be the problem? p2 physics mouse click never hits my dude

function create() 
{
game.world.setBounds(-2000, -2000, 4000, 4000)
game.physics.startSystem(Phaser.Physics.P2JS);
player = game.add.sprite(0, 0, 'dude')
game.physics.p2.enable(player,true);
game.input.onDown.add(mouseClick, this);
}

function mouseClick(pointer)
{
  var bodies = game.physics.p2.hitTest(pointer.position);
}

i click on a dude at 0,0 and "bodies" is always empty. And in console a console.log(pointer) and that's what I see...

pointer x.y:

x:477
y:311

position:

x:933
y:301

Does anybody know why that could be?

Link to comment
Share on other sites

Seems the Answer is: There is no resultive coordinates for hittest in Phaser so as I did:

game.camera.focusOnXY(0, 0)
game.camera.follow(player);

I did then this:

var x=game.camera.x +pointer.position.x;
var y=game.camera.y +pointer.position.y;
var bodies = game.physics.p2.hitTest({x:x,y:y});

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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