May be not a bug or maybe that i don't understand well how "hitTestPoint" works or simply i expected different behavior from "hitTestPoint" here is the problem:
hitTestPoint return ALWAYS true also if the sprite tested is not visible in stage or even not present in stage.
attached and example.
example 1 - run fine
example 2 - sprite is not visible but if you click/touch in the middle of the screen hitTestPoint return true
example 3 - sprite is not visible and not in stage but hitTestPoint return true.
from the Gideros DOCS:
============================================================
Sprite:hitTestPoint(x, y)
Checks whether the given coordinates (in global coordinate system) is in bounds of the sprite.
Parameters:
x: (number)
y: (number)
Returns:
true if the given global coordinates are in bounds of the sprite, false otherwise.
============================================================
i understand that Sprite:hitTestPoint "simply" test if a point is in sprite bounds so technically it works fine but
would not be better to return false if the sprite is not visible or not on the stage ...
actually if the sprite is not visible or not in stage this wasn't really touchable ...
i could be wrong do not know...
what do you think ??
zip
zip
TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com
Comments
And if people want it that way, they can always add :isVisible() on the checking.
And it probably would not be wise to change it not to break any existing codes. But then this should be something mentioned as a warning at least in the docs
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
the problem is not that Sprite:hitTestPoint(x, y) detect a hit if you touch the "transparent" part of a sprite (ex. a circle hittest detect hit on over his bounds)
the problem is that it detect hit even on a sprite that is not on stage or is not visible (setVisible(false))
this (if not in stage or setVisible(false)) apper to me not very logical...
when you have defined many sprites (in my situation game GUI gfx buttons) that are not in stage became very difficult to deal with this behviator ...
and adding isVisible on lua code seems to me a little bit odd.
... if a sprite is not on stage how can you touch it ? ...
maybe that if a sprite is not visible can be useful (as said by @tkhnoman) but when i remove a sprite from stage is that because i don't want it on stage nor touchable!.
www.tntengine.com
About not in stage, it because it detect x,y and compare it with the sprite's bound.
Even the sprite is removed from stage, the placement is the same, that is why it returned true?
If i can remember, i realized about this long time ago, and think that it was normal. That is why in my touch implementation, i used only one Event.TOUCHES_BEGIN, and do something like:
for k,v in pairs(touchHolder) do
--- check hittest and do funct
end
And i put all things that i want to be touchable to the table, and remove if i don't want it. I also control things that i don't want to be touched together this way.
now modified my code to works in this way...
but i'm always convinced that Sprite:hitTestPoint should not return true if a sprite is removed from stage.
in this way there will be "less check code" in game code.
www.tntengine.com
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
I agree with you though, I don't think hit tests should ever return true when an object is not even on the stage.
Best regards
Likes: Platypus
Likes: tkhnoman