Page 1 of 1

dragable delay

Posted: Tue Dec 10, 2024 10:56 pm
by daegan
hey, complete beginer in coding and game making here. i managed to make a dragable rectange but it's pretty delayed, this results in the mouse going out of the rectange wich makes the mouse stop moving it. have any tips? thanks!

also the code is pretty messy since im adding other thing as well, sorry...

Re: dragable delay

Posted: Wed Dec 11, 2024 1:03 am
by Hugues Ross
Well, for starters you don't need to disable rect.indrag when the mouse goes outside the rectangle. That way, the only way for a drag the user has started to end is when they let go of the mouse button. If you're making a game where the drag can be cancelled by the box being prevented from reaching the mouse (ie. walls restricting where the box can go) I'd still use a different check, probably something like a raycast to see if the box can reach the mouse or not.

Anyway, I'm no expert on this subject but I think the reason the drag hangs behind the mouse is that the logic & rendering of the game are happening independently of your OS receiving hardware events and your GPU rendering a hardware cursor. Which makes sense--you wouldn't want your entire computer tied to a game's framerate. In theory, you could 'fix' this visually (the drag issue you're having wouldn't change) by hiding the mouse and rendering your own cursor at the position love reports the mouse being at...not sure if that's really an ideal solution and I probably wouldn't bother, but I'm pretty sure that'd work.

Re: dragable delay

Posted: Thu Dec 12, 2024 6:59 pm
by daegan
Hugues Ross wrote: Wed Dec 11, 2024 1:03 am Well, for starters you don't need to disable rect.indrag when the mouse goes outside the rectangle. That way, the only way for a drag the user has started to end is when they let go of the mouse button. If you're making a game where the drag can be cancelled by the box being prevented from reaching the mouse (ie. walls restricting where the box can go) I'd still use a different check, probably something like a raycast to see if the box can reach the mouse or not.

Anyway, I'm no expert on this subject but I think the reason the drag hangs behind the mouse is that the logic & rendering of the game are happening independently of your OS receiving hardware events and your GPU rendering a hardware cursor. Which makes sense--you wouldn't want your entire computer tied to a game's framerate. In theory, you could 'fix' this visually (the drag issue you're having wouldn't change) by hiding the mouse and rendering your own cursor at the position love reports the mouse being at...not sure if that's really an ideal solution and I probably wouldn't bother, but I'm pretty sure that'd work.

hey, thanks! i'll see if i can fix it. the delay doesn't matter that much but it would be pretty fun to try drawing a cursor where the game thinks it is, might do that just for fun :crazy: