Is there a way to find the mouse position in init?
I’m hiding/showing/following a certain gui object if the mouse is inside the game window or not and I’d love to set the position of this object even if there is no mouse movement (yet).
Everything works once I start receiving data from on_input.
This seems to work too, the code in @WhiteBoxDev 's post - this position prints even if the mouse has not moved yet:
function on_input(self, action_id, action)
if not action_id then -- action_id == nil, so this is a mouse movement event
print("Mouse x position = " .. action.x)
print("Mouse y position = " .. action.y)
end
end
This doesn’t seem to be the case. Launcing from the editor or the exported bundle, on_input doesn’t fire until mouse is moved, which is the expected behaviour.
Also can’t seem to fully grasp the data coming from defos. Which space is that one in?
If the mouse has not moved yet it isn’t in the window, even if is sitting on top of the window. So you should treat it as not being in the window until it moves. So the initial position of the mouse is outside the window.
Your application should not be focus stealing from the window manager, it should wait for a signal. Although I like ‘focus strictly under mouse’ it often does not work very well. Responding to mouse click or movement is safest, which is an on_message thing.