Difference between event.global_pos() and Canavasitem.get_global_mouse_pos()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By molamar
:warning: Old Version Published before Godot 3 was released.

Hi there,
was wondering that if my root node is pos 0.0 event.global_pos() and Canvasitem.get_global_mouse_pos() differ. event.global_pos depends from Viewport/Camera and CanvasItem.get_global_mouse_pos gives me as expected the absolut World Coordinates. So, okay i guess i can handle this but can someone maybe give me a hint if i have some error in reasoning.
thx in advance!

:bust_in_silhouette: Reply From: avencherus

What exactly is event.global_pos?

The CanvasItem global mouse returns coordinates based on the viewport, and the local method is based on the CanvasItem’s local coordinates. So it’s relative from it’s origin.

If you have a node that’s a canvas item, and it lives at 100, 100. If you point your mouse in the center of it, global coordinates should report as 100, 100, and local will be 0, 0, the origin of the node.

event from the func _input(event) callback
there is event.pos and event.global_pos and i was wondering that both seems to be the same.
i would expect that event.pos is affected from the viewport transform or from that node´s transform where the script attached is.
get_global_mouse_pos gives me what i want, so far so good, but it leaves me with some questions:

Global means… yeah global? there where in the Godot Editor the two orthogonal lines intersect, an absolut reference point with the values 0,0 the origin of the big bang :wink:

How would a scene be designed where any node with a _input callback gives different values for event.pos and event.global_pos?

molamar | 2016-10-22 20:44

Oh the positions for the mouse click events.

As far as I can tell, it’s as you say, the same thing. I suppose maybe it’s just a redundancy. Anytime I’ve encountered a pos() without any local or global prefix, it’s been an absolute position.

I was thinking maybe sub-viewports might report differently, but the unhandled mouse clicks don’t seem to register in them. So I can’t think of a situation where you could get these values to diverge.

avencherus | 2016-10-22 22:59