Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
HitTestPoint behavior... — Gideros Forum

HitTestPoint behavior...

GregBUGGregBUG Guru
edited March 2013 in Bugs and issues
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 ??

TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
www.tntengine.com

Comments

  • No. I always use an invisible Rectangle or such around an object that is too small to touch, I don't want to change all of my code regarding to this.
    And if people want it that way, they can always add :isVisible() on the checking.
  • ar2rsawseenar2rsawseen Maintainer
    @GregBUG yes basically what @tkhnoman hitTestPoint is really awesome for this kind of stuff.
    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 ;)
  • BJGBJG Member
    (Current behaviour seems logical to me...it's not just about touching visible objects but can also be used for other scenarios.)
  • It would make more logical sense if there was a flag on the object like .allowEventsOffStage = true to spawn events. That way the developer can benefit from the faster native processing rather than using Lua code cycles to test for testing the :isVisible() etc.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.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
  • GregBUGGregBUG Guru
    edited March 2013
    it is possible that I not be well explained ...

    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!.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    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.

  • GregBUGGregBUG Guru
    edited March 2013
    @tkhnoman yes.
    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.
    TNT ENGiNE for Gideors Studio - Particle Engine, Virtual Pad, Animator Studio, Collision Engine - DOWNLOAD NOW !!! IT'S FREE!!! -
    www.tntengine.com
  • @greg, @tjhnoman, my point still remains that if there are lesser events generated by Gideros then the app would be faster as it would not involve looping through each event using lua.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.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
  • bowerandybowerandy Guru
    edited March 2013 Accepted Answer
    @GregBUG in the GiderosCodingEasy library by @ar2rsawseen there is a function, Sprite:isVisibleDeeply() that checks to see if a sprite is visible by checking the visibility flag of each of its parents. I always use this in conjunction with hitTestPoint() to see whether a touch on an object is valid.

    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

    +1 -1 (+1 / -0 )Share on Facebook
  • BJGBJG Member
    edited March 2013
    In general though, isn't it a good thing to keep functions generic and multi-purpose...? hitTestPoint is only being discussed here in relation to touch events, but it could be used more widely than that...eg, for collision events. By tailoring it to return special values for use with screen touching, you're restricting its wider applications. I see "check coordinates are within sprite bounds" and "check sprite is within the stage hierarchy" or "check sprite visibility" as different things. After all, it's not difficult to create a function that combines them if that's what you want.

    Likes: tkhnoman

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.