This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

how to make game pause if mouse outside viewport or game screen? i try to use this
but keep get return value everytime i move my mouse.
NOTIFICATIONWMMOUSEENTER
NOTIFICATIONWMMOUSE
EXIT

this my current code. work and not work because need to - 1 pixel or more.

func _ready() -> void:
    global_position = get_viewport().size/2

func _input(event: InputEvent) -> void:
    if get_global_mouse_position().x > 1270 or get_global_mouse_position().x < 10 or get_global_mouse_position().y < 10 or get_global_mouse_position().y > 710:
        get_tree().paused = true

    global_position = lerp((get_viewport().get_mouse_position()),global_position,0.6)
in Engine by (429 points)

1 Answer

0 votes
func _notification(what):
    if what == MainLoop.NOTIFICATION_WM_MOUSE_ENTER:
        print("Mouse inside")
        get_tree().paused = false
    elif what == MainLoop.NOTIFICATION_WM_MOUSE_EXIT:
        print("Mouse outside")
        get_tree().paused = true
    if what == MainLoop.NOTIFICATION_WM_FOCUS_IN:
        print("focus in")
    elif what == MainLoop.NOTIFICATION_WM_FOCUS_OUT:
        print("focus out")
        pause_mode = true
by (200 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.