I have a class that inherits from CCNode. I want to override the adding of this class to a parent.
So if ClassA inherits CCNode, I add it like this [self addChild:ClassA];
. ClassA contains 3 sprites and I want all 3 of those added when I add ClassA. Is there a way of doing this?
I looked into addChild
and saw that it calls setParent on the child, so in ClassA I override setParent to do this:
- (void) setParent:(CCNode *)parent {
[super setParent:parent];
[parent addChild:_sprite1 z:kZClassA];
[parent addChild:_sprite2 z:kZClassA];
[parent addChild:_sprite3 z:kZClassA];
}
Seems kinda hacky to me? Is there a better way of doing this?