Jump to content

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


Techbot
 Share

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

 

whereas

 

  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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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