accessing cocos2d children
so i have code like this
CCLabelTTF *label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%@", SomeString] fontName:@"Marker Felt" fontSize:25];
[SomeClassVar addChild:label];
Then i want to try to access it later on by -
[((SomeClass*)SomeTempClassVar).label color] = ccc3(255-pIntVal*150 ,255-pIntVal*55,255-pIntVal*50);
but i know that's not right as SomeClass doe开发者_开发知识库sn't have a label as part of it's class, rather it's a child... any help? thanks
I like to use tags. It works well in iterators and you can start at like 100 for some objects and have anything below that be a specific static object you might want to refer to. You could even use #define to do something like #define kMySprite 1
.
[SomeClassVar addChild:label z:0 tag:1];
And later access it with:
[YourScene getChildByTag:1];
http://www.cocos2d-iphone.org/api-ref/latest-stable/interface_c_c_node.html#a865a57d2fe81b5afa91a984f8cd3e986
精彩评论