Jump to content

How do I access world co-ordinates for pointer? (diablo style)


Recommended Posts

console.log (pointer.x) work fine but

console.log (pointer.worldX) shows up undefined.


I am trying to get my player sprite to move to the point clicked within the playable area. (think diablo)


I can use scrollable viewport with cursor keys, but once I try mouse click I end up going around in circles.


 sprite.rotation = game.physics.arcade.moveToPointer(sprite, 600);

is fine (it does not need world co-ordinates) but it is constantly in action , ie it does not wait for mouse click




  sprite.rotation = game.physics.arcade.moveToXY(sprite,x,y);


would be nice if paired with


 game.input.onDown.add(moveBall, this);/ / update destination with world co-ords function moveBall(pointer) {      x = pointer.Worldx;    y = pointer.WorldY; }


Any help at all would be great.


Link to comment
Share on other sites

If you've copied and pasted your code in above, then Worldx and WorldY are not the same as worldX and worldY (JS is case sensitive) - so this may explain why you're getting 'undefined'. To get the world coordinates when using a camera, all you need to do is add the camera coordinates to the pointer coordinates:

var worldX = this.game.world.camera.x + this.game.input.activePointer.x;var worldY = this.game.world.camera.y + this.game.input.activePointer.y;

This is in fact how worldX and worldY are calculated within the Pointer object: http://docs.phaser.io/Pointer.js.html#sunlight-1-line-738

Link to comment
Share on other sites


  • Recently Browsing   0 members

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