2011-10-03 24 views
2

私はこのコードの助けが必要です。タグに基づいてボタンを無効/有効にするコードを書く方法がわからない 「[levelMenu setIsEnabled:false];」を使用しようとしました。すべてのボタンは無効になっています。私のinitメソッドタグに基づいてボタンを無効にするにはどうすればよいですか?

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"texture.plist"]; 
    CCSpriteBatchNode *colorSprites = [CCSpriteBatchNode batchNodeWithFile:@"texture.png"]; 
[self addChild:colorSprites]; 

    CCMenu *myMenu = [CCMenu menuWithItems:nil]; 

    int rows = 2; 
    int cols = 4; 
    static int padding=20; 

    for(int count=0; count < (rows*cols); count++) { 

    int index1 = count +1; 
    NSString *spritefiles1 = [NSString stringWithFormat:@"sprite%d.png", index1]; 
    random1 = [CCSprite spriteWithSpriteFrameName:spritefiles1]; 

     CCMenuItemSprite *levelMenu = [CCMenuItemSprite itemFromNormalSprite:random1 selectedSprite:[CCSprite spriteWithFile:@"Iconselected.png"] disabledSprite:[CCSprite spriteWithFile:@"Iconlocked.png"] target:self selector:@selector(levelSelected:)]; 

     int yOffset = padding+(int)(random1.contentSize.width/2-((random1.contentSize.width+padding)*(count/rows))); // or /cols to fill cols first 
     int xOffset = padding+(int)(random1.contentSize.width/2+((random1.contentSize.width+padding)*(count%rows))); // or %cols to fill cols first 
     levelMenu.position = ccp(xOffset, yOffset); 

     levelMenu.tag = count+1; 
     myMenu.position =ccp(0,300); 
     [myMenu addChild:levelMenu]; 

     //testing to disable the button 
     // [levelMenu setIsEnabled:false]; 

    } 

-(void) levelSelected:(CCMenuItemSprite*) sender { 
int level = sender.tag; 
NSLog(@"test button number %d",level); 
} 

答えて

関連する問題