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?
Thanks ahead of time <3
How to Solve Mouse Clicks on Multiple Layers?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 8
- Joined: Sat Sep 12, 2015 12:34 am
Re: How to Solve Mouse Clicks on Multiple Layers?
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.
-
- Prole
- Posts: 8
- Joined: Sat Sep 12, 2015 12:34 am
Re: How to Solve Mouse Clicks on Multiple Layers?
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 elseveethree 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.
thanks
Re: How to Solve Mouse Clicks on Multiple Layers?
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.
-
- Prole
- Posts: 8
- Joined: Sat Sep 12, 2015 12:34 am
Re: How to Solve Mouse Clicks on Multiple Layers?
I like that idea a lot, and now feel dumb for not thinking thatPlu 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.
Who is online
Users browsing this forum: No registered users and 6 guests