Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
parent sprite isn't visible but childsprite is visible? — Gideros Forum

parent sprite isn't visible but childsprite is visible?

bysregbysreg Member
edited September 2012 in General questions
So,
I try to setVisible = false to parentSprite, parentSprite has a child which is childSprite. but the childSprite:isVisible() return true. is this the expected behaviour? i mean when a parent isn't visible on the screen, then the child mustn't be visible too right?

thanks

Comments

  • bowerandybowerandy Guru
    Accepted Answer
    Hi @bysreg,

    Yes, you're right. Although childSprite won't be visible on screen it is still marked as visible by it's visibility flag. One of the first helper functions I wrote was this:
    function Sprite:isVisibleDeeply()
    	-- Answer true only if the sprite and all it's a parents are visible. Normally, isVisible() will
    	-- return true even if a sprite is actually not visible on screen by wont of one of it's parents
    	-- being made invisible.
    	--
    	local try=self
    	while (try) do
    		if  not(try:isVisible() and try:getAlpha()>0) then
    			return false
    		end
    		try = try:getParent()
    	end
    	return true
    end
    Then you can just call:
    if childSprite:isVisibleDeeply() then
    You can either just copy this method into your own code or you might want to take my BhHelpers library since it contains this and several more useful functions. You can get BhHelpers off GitHub. Make sure you read the README for where to place it on disk.

    best regards
  • bysregbysreg Member
    edited September 2012
    thanks @bowerandy for the answer

    all right. i'll check your code.

    and i suggest it should be reflected in the reference document
Sign In or Register to comment.