I want to iterate through the children of a layer. What is the best way to do this? I tried retrieving the layer's children array property but that didn't work.
Best way to iterate through node children?
(6 posts) (5 voices)-
Posted 2 years ago #
-
What I do is:
for(id *item in myLayer.children)
{
...
//and if I want to make sure the child is the type I want:
if([item isKindOfClass:[Sprite class]])
{...}
}
Posted 2 years ago # -
Conceivably that should work jota but when I try it I am getting the error...
error: Type of accessor does not match the type of property "children".
Ever encountered that before?
Posted 2 years ago # -
What version of cocos are you using? Make sure in CocosNode.h its defined as:
@property (readonly) NSArray *children;
Posted 2 years ago # -
Got the same error with GCC 4.2 and SDK 3. A quick googling found this:
http://lists.apple.com/archives/Xcode-users/2008/Jul/msg00291.htmlI changed in CocosNode.h from NSArray the property to:
@property (readonly) NSMutableArray *children;And now it works.
(wtf???)
Posted 2 years ago #
Reply
You must log in to post.