How to detect if a mouseclick is inside an objects collision shape? [SOLVED]

svintaj

  • *
  • Posts: 298
I have a button with a triangular shape that I need to test if it has ben pushed or not. Is there a simple way to do this?   

« Last Edit: April 05, 2019, 01:34:50 am by svintaj »

merrak

  • *
  • Posts: 2516
The math way would be to solve the same problem Omniso described in the thread currently below yours: http://community.stencyl.com/index.php/topic,58414.0.html

Another way I can think to do this is to create a tiny, invisible actor where the mouse is clicked. Then have the button react to the "mouse click actor" colliding with it, rather than having the button react to the click itself.

designpeg

  • *
  • Posts: 700
You could use get pixel colour - it will return 0 if your click lands on a transparent part of the actor. If your actors overlap, you'd need to make a list of affected actors, then select the one with the higher drawing order to make sure you got the one on top.

svintaj

  • *
  • Posts: 298
Thanks Merrak and Designpeg for your good suggestions!

I ended up using Merraks idea, by using an invisible "Mouse Click Actor" born at the mouse when the button is klicked. Then the button react on that collision with the "Mouse Click Actor".

It was quite easy implemented in just a few minutes.