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?
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.
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
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.
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