I’ve run into a strange issue where gui.get_screen_position() works if it’s called on init() and then re-used. But if it’s called after init(), and the screen has been resized, it returns the wrong position.
Please see a minimal example: Archive.zip (38.1 KB)
Scenario 1:
Click the screen
The rectangle travels from and to the right place
Scenario 2:
Resize the window
Click the screen
The rectangle travels from and to the wrong place
On init() I store the get_screen_position() of the rectangles, and if they are re-used it works(!). I demonstrate this by firing a rectangle automatically after 3 seconds, which always move from and to the right place, regardless of screen resize.
I noticed that @AGulev has posted something that might solve this here, but I thought I’d see if this is expected behaviour or if I’m missing something.
If you wanna set screen position to a node, you need to convert screen position into node local space position.
Unfortunately, for now, we don’t have API method for a simple set of the screen position, that’s why I wrote this temporary set_screen_position() solution, this method convert screen position to local position taken into account all transformation matrix that you need to apply.
So this is what I’ve bumped into? How can the very strange behaviour above be explained, though; it WORKS if the original positions are used, rather than the current ones.
Thanks! Check out the first example I posted above. A rectangle node should move from the position of another rectangle node in a different collection. The reason nothing happens in the most recent project is that the rectangle is set to a position of vmath.vector3(inf, inf, 0), wherever that may be!
As I told you, it is possible using set_screen_position() module. Could you pls create an example where I can reproduce your problem?
I can’t reproduce (inf, inf, 0) issue in GuiScreenPosition.zip example
This example only tries to position a cloned node in the same place as a node from a different collection. The resulting position of the cloned node is (inf, inf, 0).