Mouse versus Touch

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Mouse versus Touch

Post by Ref »

Have written a simple function to detect mouse interaction with a given area of the screen.

Code: Select all

listbox.contact 	= function( x, y, w, h )	-- mouse over/clicked rectangle
	local contact, hover
	local mx, my = love.mouse.getPosition( )
	if mx > x and my > y and mx < x+w and my < y+h then
		hover = true
		if love.mouse.isDown( 1 ) then contact = true end
	end
	return hover, contact
end
Works exacted as expected when using the mouse.
However, I found that it also works for Touch EXCEPT that if I touch within the area, it indicates that I am still hovering over it even after I remove my finger.
Is this expected behavior?
Is there a way to turn off hover when the touch is no longer in contact with the screen?
Tried setting hover, mx and my to nil or false - no effect.
Only way to disable is to touch somewhere else on the screen.
I realize that that is how the mouse reacts but it seems strange that when there is no touch contact that the last touch response would be retained.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Mouse versus Touch

Post by pgimeno »

Well, it seems normal that getPosition retains the latest values. What position did you expect to get when your finger is lifted from the screen?
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Mouse versus Touch

Post by Ref »

You're right but it just seemed strange that a value would continue to be returned when there was no longer any contact.
With the mouse, the mouse is still actively over the selected area while the finger is no longer on the screen -
mx, my = love.mouse.getPosition( ) returning values even when no contact is being made.

The reason that it does is because it moves the mouse to the touch location - something that I hadn't noticed.
Attached script shows the issue.
Just trying to develop some logic for use.
Attachments
looking.love
lookin for answers
(98.66 KiB) Downloaded 74 times
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Mouse versus Touch

Post by pgimeno »

Imagine for a moment that you're a developer of Löve 0.10, and you're implementing mobile support. For the benefit of applications that aren't prepared to handle touchscreens but have mouse support, you decide to try to implement some kind of mouse emulation, so that these applications can kinda get away with that basic emulation. How do you implement love.mouse.getPosition() when the touch is released?

Option 1: return the coordinates of the last touch. It was in a good position right before the user lifted your finger anyway.
Option 2: return some position off the screen, since the "finger" is not in the screen anyway. But the application may not be ready to handle that.
Option 3: return 0,0. Well, that's a mouse movement that may not be wanted.
Option 4: return nothing, or nil. That will cause most applications to crash, because they depend on a valid value.

It seems clear that the most logical option is 1.

As for your problem, maybe you could just clear hover on touchreleased. Or maybe you can try to add full support for touches, tracking their ids on touchpressed/touchreleased and so on.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Mouse versus Touch

Post by Ref »

Agree!
I just didn't anticipate that touch moved the mouse.
Now I can anticipate.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 51 guests