Quick Links: Gideros Home | Download Gideros | Developer Guide
Recursive sprite counting
  • totebototebo +1 -1
    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
    return count;

    Likes: totebo

  • pie +1 -1 (+2 / -0 )
    The problem are the nested ones, maybe you could try to merge print_r with this:

    Or modify print_r to keep a counter when getBaseClass returns Sprite

    [Edit: mertocan was faster! :) ]

    Likes: totebo, antix

  • totebototebo +1 -1
    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