Skip to content

Commit 8a922af

Browse files
authored
Merge pull request #9835 from HubbleCommand/master
2D movement overview - Click-and-move - use actions
2 parents f4a38c9 + 8a868a4 commit 8a922af

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

tutorials/2d/2d_movement.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ on the screen will cause the player to move to the target location.
231231
var target = position
232232

233233
func _input(event):
234-
if event is InputEventMouseButton:
235-
if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
236-
target = get_global_mouse_position()
234+
# Use is_action_pressed to only accept single taps as input instead of mouse drags.
235+
if event.is_action_pressed(&"click"):
236+
target = get_global_mouse_position()
237237

238238
func _physics_process(delta):
239239
velocity = position.direction_to(target) * speed
@@ -254,12 +254,10 @@ on the screen will cause the player to move to the target location.
254254

255255
public override void _Input(InputEvent @event)
256256
{
257-
if (@event is InputEventMouseButton eventMouseButton)
257+
// Use IsActionPressed to only accept single taps as input instead of mouse drags.
258+
if (@event.IsActionPressed("click"))
258259
{
259-
if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed)
260-
{
261-
_target = GetGlobalMousePosition();
262-
}
260+
_target = GetGlobalMousePosition();
263261
}
264262
}
265263

0 commit comments

Comments
 (0)