Suggestion: mousemoved() callback

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Suggestion: mousemoved() callback

Post by surtic »

There seems to be a small problem with having to poll to find the position of the mouse. For example, if I want to drag something (see file attached), then the object doesn't move together with the mouse.

My suggestion is to have a mousemoved(x, y) callback to allow the application to deal with this event as it happens. In most cases the callback will not be implemented, but sometimes it can be quite useful.

Of course, I can draw the cursor myself, but that's not always the best solution (in a windowed application the user might expect to see the standard cursor).
Attachments
drag.love
(400 Bytes) Downloaded 233 times
User avatar
Xfcn
Citizen
Posts: 65
Joined: Sat Jul 12, 2008 6:53 am

Re: Suggestion: mousemoved() callback

Post by Xfcn »

I'm not entirely certain what your problem is? The example works perfectly for me with no noticeable lag or anything. I click the square and drag it and the cursor remains and the square is dragged around. WFM.
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Suggestion: mousemoved() callback

Post by surtic »

I must have a slow computer (or graphics card)... didn't think that was the case, it was great when I bought it...

I can certainly see a lag - if I grab the rectangle by the corner and then move it in that direction (the corner's direction) the mouse is outside the rectangle most of the time.

In any case, for a fast computer it won't make a difference if mousemoved() was implemented (the performance hit would be minimal, especially if it's not actually used), whereas for a slow computer it would be very useful.

I'm wondering if I'm the only one with this problem, though...
User avatar
Xfcn
Citizen
Posts: 65
Joined: Sat Jul 12, 2008 6:53 am

Re: Suggestion: mousemoved() callback

Post by Xfcn »

This breaks the "drag from the original click point" portion of the code, but purely for testing purposes see if this doesn't help:

Code: Select all

function update(dt)
   if drag.active then
      local x, y = love.mouse.getPosition()
      rect.x = x - drag.dx * dt
      rect.y = y - drag.dy * dt
   end
end
"Any sufficiently advanced technology is indistinguishable from magic." - Arthur C. Clarke
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Suggestion: mousemoved() callback

Post by surtic »

Thanks for the suggestion. Unfortunately it doesn't help - the cursor is still outside the rectangle most of the time.

I guess for now I'll have to draw the cursor myself - not a big deal, but maybe something to think about for the next version of LÖVE.
User avatar
rude
Administrator
Posts: 1052
Joined: Mon Feb 04, 2008 3:58 pm
Location: Oslo, Norway

Re: Suggestion: mousemoved() callback

Post by rude »

The lag is probably due to vertical sync, which can be disabled by setting vsync = false in game.conf. (Unless you've specified "always sync" in your graphics driver settings). Adding mousemoved() will not solve this problem, since events aren't processed while waiting for vertical sync.

Future solutions may involve multi-threading, or setting the actual mouse cursor itself.
surtic
Citizen
Posts: 74
Joined: Sat Jul 12, 2008 12:18 am

Re: Suggestion: mousemoved() callback

Post by surtic »

Thank you very much! It solved the problem immediately...

Now I'm happy again :)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest