Set .alpha = 0 and :addEventListener doesn't work

Hello. I have some transparent area where player can touch, code sample:

local touchArea = display.newRect( params )
touchArea.alpha = 0
touchArea:addEventListener ( "touch", function )

if I set touchArea.alpha = 0.01 it works. If alpha = 0 it doesn’t work. What is wrong?

The problem with touchArea.alpha = 0.01 is also strange. The touchArea keep existing after the scene destroying when I quit to the menu (but it set as local and even exist only in this scene!), and after some this scene reloads, I can definitely see it, so it forms layers. 10 reloads <=> 10 layers <=> .alpha = 0.1

The answer is that an invisible object can’t be touched unless explicitly specified. Having an alpha value of 0.01 means that the display object isn’t fully invisible. If you wish to make an object completely invisible and still be able to touch it, you’ll need to specify touchArea.isHitTestable = true.

Also, display objects aren’t automatically cleaned up between scene transitions unless you add them to the scene display group.

1 Like

Thank you XeduR! Again and again! ‘.isHitTestable = true’ worked for me!

The second hint was also correct, somehow I missed adding the touchArea to the scene display group.