Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Disable click through overlapping shapes?  (Read 1357 times)

0 Members and 2 Guests are viewing this topic.

Chiggy_Playz

  • Newbie
  • *
  • Posts: 15
    • View Profile
Disable click through overlapping shapes?
« on: April 20, 2019, 05:42:31 pm »
I am really close to building my project but I am encountering one simple problem. I have a rectangle on which I have use the GetGlobalBounds to check if mouse clicks on it. Now I am drawing over another Rectangle over that rectangle and using GetGlobalBounds on the overlapping Rectangle. Now when i click on the overlapping one, the command for the original Rectangle is executed instead of the one that is overlapping. How can I prevent this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: Disable click through overlapping shapes?
« Reply #1 on: April 20, 2019, 11:45:31 pm »
The events don't know of your render order, as such, you'll have to introduce your own depth/z-ordering.
That way your event processing would start at the upper most layer, where you then can also mark the event consumed and don't let is pass down to lower levels.
You can also make this simpler, but in the end, you'll have to somehow track what is at which depth.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/