It seems that Sprite:hitTestPoint() does not ignore hidden children that have been set to hidden using :setVisible(false).
If I have a sprite (f.e. button) that contains several children and do a :hitTestPoint, I would assume that children whose alpha is 0 are taken into account, whereas children set to hidden ( :setVisible(false) ) are ignored.
Shouldn't this be the usual way?
Comments
setVisible removes the image from the rendering, but still leaves its dimensions to impact the surrounding sprites
The reason is simple, you can create small tiny buttons with invisible area around them to make them easier to click on smaller screens
but the drawback is, well what you found out on your own
The solution is to scale them to hide them completely
You can do something like this, for easier code implementation
@MauMau, a quick fix rather than scaling, because it might mess up the layout (the sprite might be set to not visible to appear on some other action soon) is when you handle touch, simply check for the visibility along with the
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
It would make sense if objects (or children) set to alpha = 0 would receive touch events, while objects with visibility = false would be ignored. By doing so, we could decide if we'd like an object to be interactive or not.
@OZApps: I have a button (sprite) with a tooltip bubble above (child of the button sprite). Most of the time, the tooltip isn't visible -but if the user touches the tooltip area above the button, it still triggers the touch event, although there is just a blank space. hitTestPoint also includes this (hidden) children and returns a true when the user touched the (hidden) tooltip above the button.
If you would use it like a sprite (single object) the workaround might just work for you.
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
This however raises the question of whether children of invisible parents are themselves invisible according to the isVisible function...?
Likes: matty47
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps