Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
priority of the image — Gideros Forum

priority of the image

Unknown Member
edited October 2015 in General questions
Hello guys,
How can I give a set of priority of the image, so that no other image is unable to cover him?

Comments

  • hgy29hgy29 Maintainer
    Do you mean like having multiple images being children of a single Sprite, and ensuring that one of the images is at top ? If so then since images are drawn by order of additions into the parent sprite, then just add the top-most in the last position.
  • NatWobbleNatWobble Member
    edited October 2015
    If you want to change the z order relative to a parent you can try something like this:
    function myClass:toFront()
       self:getParent():addChild(self)
    end
     
    function myClass:toBack()
        self:getParent():addChildAt(self, 1)
    end
     
    function myClass:setZ(index)
            local parent=self:getParent()
            local n=parent:getNumChildren()
            if index>n then
              parent:addChild(self)
            elseif index<1 then  
              parent:addChildAt(self, 1)       
            else
              parent:addChildAt(self, index)
            end
    end
    If you have lots of sprites being generated in your game loop, you'll need to call the toFront function every frame or add any new sprites behind it when they are created - addChildAt(self, 1).

    Remember it won't work very well for "nephew"/"uncle"/"cousin" relationships. You'll need to work out some logic between the parents or use empty sprites.
Sign In or Register to comment.