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);
}