2011-10-03 7 views
2

J'ai besoin d'aide avec ce code. pas sûr comment écrire un code pour désactiver/activer le bouton basé sur une étiquette. J'ai essayé d'utiliser "[levelMenu setIsEnabled: false];" mais tous les boutons sont désactivés.comment désactiver un bouton basé sur un tag?

// dans ma méthode 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); 
} 

Répondre

Questions connexes