浏览代码

Merge pull request #9835 from HubbleCommand/master

2D movement overview - Click-and-move - use actions
Matthew 11 月之前
父节点
当前提交
83d84bb893
共有 1 个文件被更改,包括 6 次插入8 次删除
  1. 6 8
      tutorials/2d/2d_movement.rst

+ 6 - 8
tutorials/2d/2d_movement.rst

@@ -231,9 +231,9 @@ on the screen will cause the player to move to the target location.
     var target = position
 
     func _input(event):
-        if event is InputEventMouseButton:
-            if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
-                target = get_global_mouse_position()
+        # Use is_action_pressed to only accept single taps as input instead of mouse drags.
+        if event.is_action_pressed(&"click"):
+            target = get_global_mouse_position()
 
     func _physics_process(delta):
         velocity = position.direction_to(target) * speed
@@ -254,12 +254,10 @@ on the screen will cause the player to move to the target location.
 
         public override void _Input(InputEvent @event)
         {
-            if (@event is InputEventMouseButton eventMouseButton)
+            // Use IsActionPressed to only accept single taps as input instead of mouse drags.
+            if (@event.IsActionPressed("click"))
             {
-                if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed)
-                {
-                    _target = GetGlobalMousePosition();
-                }
+                _target = GetGlobalMousePosition();
             }
         }