开发者

A function is not being called

开发者 https://www.devze.com 2023-04-10 01:36 出处:网络
I got a CCNode subclass, and it eventually calls a function located on its parent. First, my class will do this:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号