I just started with cocos2D and came across something that looks like this ..
CCSprite *sprite = (CCSprite *)[self getChildByTag:13];
then I can just simply do stuff with the object.
I’m really curious with what’s happening after the ‘ = ‘ part of the code.
I know that the [self getChildByTag:13] retrieves the object by the tag I assigned to it in a previous method, the -(id)init method, and I know that by it self (CCSprite *) is just a pointer to something that will be a member of it self.. but how do these two things work together.
Basically you are fetching a
CCSpriteobject in a scene by requesting the “child” via tag.The
getChildByTagmethod retrieves the node (orCCSpritein this case… you may want to put in a bit of validation code to make sure what’s retrieved truly is aCCSpriteobject) and then assigns it to yourspritevariable (thanks to a cast you’re doing in there).Oh, here’s a related question that might help you out, too.