在Cocos2D CCMenuItem的选择器中使用GKPeerPickerController

时间:2010-03-25 01:09:56

标签: iphone objective-c cocos2d-iphone gamekit

所以我正在尝试将GameKit与Cocos2D一起使用,这样当用户点击多人游戏菜单项时,它将显示GKPeerPickerController。然而,我遇到了一些障碍。它似乎不想编译。但是,它不会在我的选择器中的代码内部给出错误。无论如何这里是代码...

@implementation GameOverLayer
- (id) init 
{
    self = [super init];
    if (self != nil) 
    {
        [CCMenuItemFont setFontSize:20];
        [CCMenuItemFont setFontName:@"Helvetica"];
        CCMenuItem *start = [CCMenuItemFont itemFromString:@"Play Again!" target:self selector:@selector(startGame:)];
        CCMenuItem *connect = [CCMenuItemFont itemFromString:@"Multiplayer" target:self selector:@selector(connect:)];
        CCMenu *menu = [CCMenu menuWithItems:start,connect, nil];
        [menu alignItemsVertically];
        [self addChild:menu];
    }
    return self;
}
-(void)startGame: (id)sender 
{
    [[CCDirector sharedDirector] replaceScene: [HelloWorld scene]];
}

-(void)connect: (id)sender
{
    GKPeerPickerController *peerPicker;
    peerPicker = [[GKPeerPickerController alloc] init];

    peerPicker.delegate = self;
    peerPicker.connectionTypesMask = GKPeerPickerConnectionTypeOnline | GKPeerPickerConnectionTypeNearby;

    [peerPicker show];
}
@end

我得到的错误信息是......

".obj_class_name_GKPeerPickerController", referenced from:
Literal-Pointer@_OBJC@_cls_refs@GKPeerPickerController in GameOverScene.o
Symbol(s) not found
Collect2: id returned 1 exit status

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

将GameKit框架添加到您的项目中,或者如果它已经存在,请确保选中其目标复选框。