2012-12-15 81 views
0

我在我的遊戲加載水平使用MenuLevel .. http://www.prioregroup.com/iphone/menulevel.aspx的Cocos2D MenuLevel如何鎖定,解鎖

目前,這一水平是否被鎖定或沒有,它的加載。如果它是鎖着的,它不應該正在加載..我該怎麼做?謝謝..

//創建菜單項

[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

你試過我的代碼嗎?它工作.. ?? –

+0

謝謝..運行良好.. – user1526474

回答

0

可以使用用戶數據屬性。在您的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:方法檢查用戶數據下面給出:

NSString *lockString = (NSString *)item.userData; 
if ([lockString isEqualToString:@"locked"]) 
{ 
    // Locked level 
} 
else 
{ 
    // Unlocked 
} 
+0

其實我想區分哪個按鈕被鎖定或解鎖..我會盡快更新我的問題.. – user1526474