convertToWorldSpace Mouse Coordinates

Hello,

Via a script I put the coordinates of the mouse in two variables. Unfortunately they are based on the position on the screen. I wish to be able to obtain them in coordinates of the world.

My node tree:

Sans%20titre%201

MouseDetecor.js:


this.node.on(cc.Node.EventType.MOUSE_MOVE, function(event) {

var mousePos = this.node.getParent().convertToWorldSpace(event.getLocation());

this.mousex = mousePos.x;

this.mousey = mousePos.y;

}, this);

Unfortunately, the result is too big.

What is the solution ?

Thank you

Ps: I hope my message is understandable.

1 Like

event.getLocation() already return world coordinates

Thank you for the answer :slightly_smiling_face:
I just checked again, at the bottom left of the screen the coordinates are always (0; 0).
So it’s relative to the screen.