Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
hitTestPoint on invisible sprite? — Gideros Forum

hitTestPoint on invisible sprite?

I have a container that have sprites in it, and I need to detect if sprite is clicked, BUT if parent is INVISIBLE then hitTestPoint still triggers.

Example code:
--[[
Sprite1 -> parent: stage
 ↳ Sprite2 -> parent: Sprite1
  ↳ Sprite3 -> parent: Sprite2
   ↳ Sprite4 -> parent: Sprite3
    ↳ px -> parent: Sprite4
]]
local t = {}
for i = 1,4 do 
	local cont = Sprite.new() 
	t[i] = cont
	if i > 1 then 
		t[i-1]:addChild(cont)
	else
		stage:addChild(cont)	
	end
end
 
local px = Pixel.new(0,1,32,32)
t[4]:addChild(px)
t[1]:setVisible(false)
 
stage:addEventListener("mouseDown", function(e)
	print(px:hitTestPoint(e.x,e.y,true))
end)
According to the wiki the third parameter "shapeFlag" supposed to solve the problem but this did not happen.
shapeFlag: (bool) Take hidden, clipping/masking into consideration when testing hit point optional
So the questions are: Is it a bug? How to fix it?)

Comments

  • hgy29hgy29 Maintainer
    It is a bug, the code seems to check visibility only on the current sprite, not its parents. One more thing to fix :)
    +1 -1 (+2 / -0 )Share on Facebook
  • i thought that's intentional, heh.
    meanwhile:
    function Sprite.isVisibleRecursive( sprite )  
      if not stage:contains(sprite) then return false end
      local visible = false
      repeat
        visible = sprite:isVisible()
        sprite = sprite:getParent()
      until sprite == nil or visible == false
      return visible
    end
  • yeah, I did same thing :)
    function Base:hitTestPoint(x,y,shapeFlag) 
    	local parent = self:getParent()
    	while parent do 
    		if not parent:isVisible() then 
    			return false
    		end
    		parent = parent:getParent()
    	end
    	return Sprite.hitTestPoint(self,x,y,shapeFlag)
    end
  • MoKaLuxMoKaLux Member
    hgy said:

    It is a bug, the code seems to check visibility only on the current sprite, not its parents. One more thing to fix :)

    Does anybody know if it's been fixed? I have tested but it doesn't seem to work for me.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Looks like (from the code) it hasn't. Doing it now.

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    thank you hgy29 :)

    Likes: PaulH

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.