How to Solve Mouse Clicks on Multiple Layers?

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
CosmicFloppyDisk
Prole
Posts: 8
Joined: Sat Sep 12, 2015 12:34 am

How to Solve Mouse Clicks on Multiple Layers?

Post by CosmicFloppyDisk »

Hi, I'm working on a game and have made some metatables for like buttons and windows, both have a handler metatable respectively called either button manager or window manager, in them is a function I run in love.update called WindowManager:doEvents() or ButtonManager:doEvents() which tests if mouse 1 is down then tests if the location of the click is on the respective object, the issue can be seen there, if two objects are overlapped they both will register clicks. I can see a way to resolve this by setting like a priority layer as they're drawn or whatever and just check at that location which object is at the top of the list although that seems it might take some time and use a bit to much processing. So my question to you fine people is do you have a simpler solution that you could share with me? :awesome:

Thanks ahead of time <3
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: How to Solve Mouse Clicks on Multiple Layers?

Post by veethree »

The simplest solution would be to design your UI so nothing overlaps. If it's an issue of both a button and a window registering mouse click events at the same time, Then If a button was clicked, Don't trigger the event in the window containing it. If it's an issue of windows overlapping, It would be a matter of re-arranging a table containing all the windows, So when a bunch of overlapping windows are clicked, the one closest to the top of the table would have the click event triggered.
CosmicFloppyDisk
Prole
Posts: 8
Joined: Sat Sep 12, 2015 12:34 am

Re: How to Solve Mouse Clicks on Multiple Layers?

Post by CosmicFloppyDisk »

veethree wrote:The simplest solution would be to design your UI so nothing overlaps. If it's an issue of both a button and a window registering mouse click events at the same time, Then If a button was clicked, Don't trigger the event in the window containing it. If it's an issue of windows overlapping, It would be a matter of re-arranging a table containing all the windows, So when a bunch of overlapping windows are clicked, the one closest to the top of the table would have the click event triggered.
Figured that would be the best solution, noting overlaps accept when you put a moveable window over a button or other window, I'll just make buttons lowest on the priority :/ still open to anything else

thanks :)
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: How to Solve Mouse Clicks on Multiple Layers?

Post by Plu »

You could give each view a z-index, and hit them in order of z-index with an option on the event to stop propagation. That's basically how HTML/Javascript does it.
CosmicFloppyDisk
Prole
Posts: 8
Joined: Sat Sep 12, 2015 12:34 am

Re: How to Solve Mouse Clicks on Multiple Layers?

Post by CosmicFloppyDisk »

Plu wrote:You could give each view a z-index, and hit them in order of z-index with an option on the event to stop propagation. That's basically how HTML/Javascript does it.
I like that idea a lot, and now feel dumb for not thinking that :D
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 66 guests