I got a CCNode subclass, and it eventually calls a function located on its parent. First, my class will do this:
-(void)getTargetPosition {
Battle *myParent = (Battle *)self.parent;
position = [myParent getTargetPosition:@"ENEMY"];
}
Where Battle is the parent (a CCLayer).
And here's the code for the function getTargetPosition in the parent:
-(CGPoint)getTargetPosition:(NSString*)target {
NSLog(@"I AM RUNNING");
CGPoint position;
if ([target isEqualToString:@"ENEMY"]) {
position = ccp(400,250);
}else if ([target i开发者_开发百科sEqualToString:@"ALLY"]) {
position = ccp(240,160);
}
return position;
}
But there is this problem: getTargetPosition is, for some reason, never called. I can tell since the NSLog "I AM RUNNING" never displays.
Any ideas why is that method not running?
The functions are all declared on the .h file already. XCode throws me no warnings/errors.
Is self.parent (and thus myParent) nil? Then the method would not be called.
精彩评论