hope anyone can help me.
I’m trying to figure out what pointer to an object is passed within a call of a method.
So (in the cocos2d environment) it would be something like this:
- (void)loadCreature:(CCSprite*)creature
{
if (/*here I want to check if the pointer is 'blue'*/) NSLog(@"the creature is blue")
if (/*here I want to check if the pointer is 'red'*/) NSLog(@"the creature is red")
}
and the implementation:
CCSprite *blue;
CCSprite *red;
[self loadCreature:blue];
[self loadCreature:red];
thanks in advance 🙂
- Yurki
Unless there is some information buried inside of the blue and red objects that differentiates them, ie:
And is set before the call to loadCreature, then there would not be any way to tell inside the loadCreature method which CCSprite object was passed to it.
The only alternative would to declare red and blue as global variables and inside loadCreature do a comparison of their pointers to figure out which is which. But that would be so wrong to do, and if I found out that you were doing this I’d get very very angry 😀