Touch on transparent

Anything libgdx related goes here!

Touch on transparent

Postby xpdt » Sun Sep 08, 2019 6:08 pm

I have a Image on the stage that has a few holes (holes are transparent). The image is touchable. How can I make disable touch for the holes.
This means that if we click on the hole, the actors behind this Image will be receive touchEvent.
What is the solution?

Image
xpdt
 
Posts: 80
Joined: Mon Jul 04, 2016 2:29 am

Re: Touch on transparent

Postby shatterblast » Sun Sep 08, 2019 7:03 pm

Assuming your "hole" object inherits from Actor, then the following should work:
Code: Select all
hole.setTouchable( Touchable.disabled );


https://libgdx.badlogicgames.com/ci/nig ... Touchable-
shatterblast
 
Posts: 406
Joined: Sun Jul 06, 2014 1:14 pm

Re: Touch on transparent

Postby xpdt » Sun Sep 08, 2019 10:07 pm

shatterblast wrote:Assuming your "hole" object inherits from Actor, then the following should work:
Code: Select all
hole.setTouchable( Touchable.disabled );


https://libgdx.badlogicgames.com/ci/nig ... Touchable-


I think you didn't understand what I meant. The black rectangle is a texture that is transparent in three parts. I've made a image (Image class) with this texture. I've named it the blackRectangle. I've added a blackRectangle in the stage.
I want the blackRectangle to be Touchable except for transparent areas (holes).
xpdt
 
Posts: 80
Joined: Mon Jul 04, 2016 2:29 am

Re: Touch on transparent

Postby shatterblast » Mon Sep 09, 2019 3:55 am

I know this is not the answer you exactly would want. You could slice up the picture into rectangles. Each area, except for the rectangles with the holes, can be set to touchable. You could put your desired response code into a single method and each of those touchable rectangles could fire off that method. I would probably put all the items into one Stage.

Otherwise, I don't see what you would lay over the Image to make certain parts untouchable. If you wanted to go really obscure, you could use something like a transparent Image in an ImageButton, with a completely transparent skin, inside a Container and set ImageButton.setDisabled( true ). Of course, there would be a performance hit with that idea, and it would probably be faster to just slice up your Image into sections.

To be funny:
https://libgdx.badlogicgames.com/ci/nig ... d-boolean-

Oh, and by the way... that was a MAYBE with the ImageButton!!! :shock: Still, the other part should work.
shatterblast
 
Posts: 406
Joined: Sun Jul 06, 2014 1:14 pm

Re: Touch on transparent

Postby xpdt » Mon Sep 09, 2019 10:13 am

shatterblast wrote:I know this is not the answer you exactly would want. You could slice up the picture into rectangles. Each area, except for the rectangles with the holes, can be set to touchable. You could put your desired response code into a single method and each of those touchable rectangles could fire off that method. I would probably put all the items into one Stage.

Otherwise, I don't see what you would lay over the Image to make certain parts untouchable. If you wanted to go really obscure, you could use something like a transparent Image in an ImageButton, with a completely transparent skin, inside a Container and set ImageButton.setDisabled( true ). Of course, there would be a performance hit with that idea, and it would probably be faster to just slice up your Image into sections.

To be funny:
https://libgdx.badlogicgames.com/ci/nig ... d-boolean-

Oh, and by the way... that was a MAYBE with the ImageButton!!! :shock: Still, the other part should work.


Thanks for your answer
I'm looking for a better way but if I don't find it I'll use your method
xpdt
 
Posts: 80
Joined: Mon Jul 04, 2016 2:29 am

Re: Touch on transparent

Postby nnaass » Fri Sep 13, 2019 6:42 pm

you can override the hit() method of that image then test that pixel and check if has alpha == zero
nnaass
 
Posts: 61
Joined: Sat Jan 25, 2014 4:44 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest