Godot Version
4.4.0-beta as well as 4.3
Question
Hi there,
I’m trying to implement simple dragging logic. Everything works fine, but when I start dragging after the initial mouse button press, I’ve noticed there a slight lag. I’ve tried to log the values, and get_global_mouse_position() simply doesn’t get updated much during the first ± sec, after that, the dragging is smooth.
Any ideas?
Here is my most simple code snippet.
using Godot;
using System;
public partial class Icon : Sprite2D
{
private bool _isHovered = false;
private bool _isDragging = false;
private Vector2 _dragOffset;
public override void _Ready()
{
var area = GetNode<Area2D>("%Area2D");
area.MouseEntered += OnMouseEntered;
area.MouseExited += OnMouseExited;
}
public override void _Process(double delta)
{
if (_isDragging)
{
GD.Print(GetGlobalMousePosition());
GlobalPosition = GetGlobalMousePosition();
}
}
public override void _Input(InputEvent @event)
{
if (@event is InputEventMouseButton mouseEvent)
{
if (mouseEvent.Pressed && mouseEvent.ButtonIndex == MouseButton.Left && _isHovered)
{
GD.Print("Pressed");
_isDragging = true;
}
else if (!mouseEvent.Pressed && mouseEvent.ButtonIndex == MouseButton.Left)
{
_isDragging = false;
GD.Print("Released");
}
}
}
private void OnMouseEntered()
{
GD.Print("Entered");
_isHovered = true;
}
private void OnMouseExited()
{
GD.Print("Exited");
_isHovered = false;
}
}