Quick Links: Gideros Home | Download Gideros | Developer Guide
Recursive sprite counting
  • totebototebo +1 -1
    Member
    How would I print the total Sprite child count of a sprite, including nested children?
    My Gideros games: www.totebo.com
  • mertocanmertocan +1 -1 (+1 / -0 )
    Member Accepted Answer
    Hi, Can you try this?
    function Sprite.getCascadeChildrenCount(self)
     
    local count = 0
     
    for i=1,self:getNumChildren() do
    count = count + self:getChildAt(i):getCascadeChildrenCount() + 1
    end
     
    return count;
     
    end
     
    print(sprite:getCascadeChildrenCount())

    Likes: totebo

  • pie +1 -1 (+2 / -0 )
    Member
    The problem are the nested ones, maybe you could try to merge print_r with this:
    http://docs.giderosmobile.com/reference/gideros/Sprite/getNumChildren

    Or modify print_r to keep a counter when getBaseClass returns Sprite

    [Edit: mertocan was faster! :) ]

    Likes: totebo, antix

  • totebototebo +1 -1
    Member
    That looks awesome, thanks!
    My Gideros games: www.totebo.com

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with Google Sign In with OpenID

In this Discussion

Top Posters