0

我在我的游戏中使用 MenuLevel 来加载关卡.. http://www.prioregroup.com/iphone/menulevel.aspx

目前,一个关卡是否被锁定,它正在加载。如果它被锁定,它不应该被加载。我该怎么做?谢谢..

// 创建菜单项

    [menu createMenuItemLevel:1 position:ccp(x, size.height / 2) life:0 locked:NO];  





- (void)menuLevel:(MenuLevel *)menuLevel buttonSelected:(id)source
{
    CCMenuItem *item = (CCMenuItem*)source;
    NSString *msg = [NSString stringWithFormat:@"You have pressed the button # %d", item.tag]; // retrieve level number.. 
            NSLog(@"MenuLevel Sample %@", msg);


// What I want is something like..  if (item.locked == YES) do something

}
4

1 回答 1

0

You can use the userData property. In your MenuLevel.m file add the following lines in

- (CCMenuItem*)createMenuItemLevel:(NSInteger)level 
                          position:(CGPoint)position 
                              life:(NSInteger)life 
                            locked:(BOOL)locked
                            target:(id)target
                          selector:(SEL)selector

method.

if (locked)
{
    item.userData = @"locked";
}
else
{
    item.userData = @"notLocked";
}

And in your buttonSelected: method check that userData as given below:

NSString *lockString = (NSString *)item.userData;
if ([lockString isEqualToString:@"locked"])
{
    // Locked level
}
else
{
    // Unlocked
}
于 2012-12-15T05:03:16.387 回答