Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Recursive sprite counting - Gideros Forum

Recursive sprite counting

totebototebo Member
edited May 2017 in General questions
How would I print the total Sprite child count of a sprite, including nested children?
My Gideros games: www.totebo.com


  • mertocanmertocan Member
    edited May 2017 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

    +1 -1 (+1 / -0 ) Share on Facebook
  • piepie Member
    edited May 2017
    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

    +1 -1 (+2 / -0 ) Share on Facebook
  • totebototebo Member
    That looks awesome, thanks!
    My Gideros games: www.totebo.com
Sign In or Register to comment.