Hi,
We are trying to export a game to HTML5 but have some problem with capturing the mouse.
We get the following error:
MOUSE_MODE_CAPTURED can only be entered from within an appropriate input callback
We set the mouse mode like this:
```
func _input(event):
if Input.is_action_just_pressed("ui_cancel"):
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
else:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
Should I use another input function or what am I doing wrong?
We're using Firefox and Godot 3.0
I think you'll need a button so the user has to manually click on it (like fullscreen). This calls func on_button_pressed()
You can only capture the cursor from a press/release event (i.e. not from mouse/joy motion or screen drag events). Check the class of the event passed to the callback and call set_mouse_mode accordingly.
for others having trouble, i fixed it by creating two new key maps for mouse_capture and mouse_release and adding this code in my script
func _input(event):
if Input.is_action_just_pressed("mouse_capture"):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if Input.is_action_just_pressed("mouse_release"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
Most helpful comment
for others having trouble, i fixed it by creating two new key maps for
mouse_captureandmouse_releaseand adding this code in my script