开发者

Cocos2D getChild caused not declared in scope error

When trying to compile the following code for iphone in xcode

void removeGrid(int x,int y) {
    //for(id *item in self) {
        //if(item.position ==  ccp(x*32, y*32)) {
        //  printf("good");
        //}
        //printf("%@",item);
//  }
    char rrs[8];
    sprintf(rrs,"01%d%d",x/32,y/32);
    int aTag = [[[NSString alloc] initWithBytes:rrs length:sizeof(rrs) encoding:NSASCIIStringEncoding] intValue];
    //NSAssert( aTag != kCCNodeTagInvalid, @"Invalid tag");

    CCNode *child = [self getChildByTag:aTag]; //here it is simply getting a single chil

    if (child == nil)
        CCLOG(@"cocos2d: removeChildByTag: child not found!");
    else
        [self removeChild:child cleanup:true];
}

The compiler says "self was not declared in this scope". I开发者_如何学JAVA'm new to objc and cocos2d, but this seems to be the way most tutorials access objects in the scene. Am I missing something?


Solved. This turned out to be one of Xcode's quirks. Since the function declaration was in c++, it was not able to access objective c self functions for some reason. Changing the declaration to an objective c allowed it to access all the functions. Doesn't make much sense to me, but it now works fine.

For those of you wondering, yes, the file had a .mm extension.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜