我在游戏中使用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
}
答案 0 :(得分:0)
您可以使用userData属性。在MenuLevel.m
文件中,在
- (CCMenuItem*)createMenuItemLevel:(NSInteger)level
position:(CGPoint)position
life:(NSInteger)life
locked:(BOOL)locked
target:(id)target
selector:(SEL)selector
方法
if (locked)
{
item.userData = @"locked";
}
else
{
item.userData = @"notLocked";
}
在您的buttonSelected:
方法中,检查下面给出的userData:
NSString *lockString = (NSString *)item.userData;
if ([lockString isEqualToString:@"locked"])
{
// Locked level
}
else
{
// Unlocked
}