2

我看到我可以用它event.is_pressed()来检查何时发生了点击(我假设是点击)。但是当 LMB(鼠标左键)仍然按下时任何额外的动作,不等于true使用is_pressed()

这是我用于此测试的代码块:

func _input(event):
    var tilemap = find_node("TileMap")
    if(event.is_pressed()):
        tiles.highlight(event.position)

当我实际单击时,tiles.highlight()会调用,但是当我在 LMB 仍然向下的情况下移动鼠标时,它不会调用tiles.highlight(). 我需要在这里使用不同的功能吗?

4

1 回答 1

3

You can use polling to see if the mouse button is being held down.

func _ready():
    set_process(true)

func _process(delta):
    if Input.is_mouse_button_pressed(1):  # Left mouse button.
        print('Left mouse button pressed. ', get_viewport().get_mouse_position())

Otherwise, you can set a variable, for example mouse_button_pressed, to true or false in the _input function when a mouse button is pressed or released and then check it in the _process function:

func _input(event):
    if event is InputEventMouseButton:
        if event.is_pressed():  # Mouse button down.
            mouse_button_pressed = true
        elif not event.is_pressed():  # Mouse button released.
            mouse_button_pressed = false

func _process(delta):
    if mouse_button_pressed: 
        print('Left mouse button pressed. ', get_viewport().get_mouse_position())
于 2018-02-10T16:19:05.127 回答