Reputation: 10752
CCMenu,CCMenuItem,CCMenuItemToggle toggle is Deprecated in Cocos2d 3.0.I want to set toggle button in cocos2d 3.0.
I found below method in 3.0 But it's not working.
CCButton *soundOnBtn == [CCButton buttonWithTitle:@""
spriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOn.png"]
highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOnSelected.png"]
disabledSpriteFrame:nil];
CCButton *soundOffBtn= [CCButton buttonWithTitle:@""
spriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOff.png"]
highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOffSelected.png"]
disabledSpriteFrame:nil];
Pls, help me... Thanks in Advance...
Upvotes: 1
Views: 4936
Reputation: 298
So I assume you want a toggle button to enable/disable the sound.
You can do this only by having one button with two states: Sound enabled (not selected) and sound disabled (selected).
Try this, maybe you will still have to change some parameters when it is in selected state:
CCButton *soundTriggerBtn = [CCButton buttonWithTitle:@""
spriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOn.png"]
highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOff.png"]
disabledSpriteFrame:nil];
soundTriggerBtn.togglesSelectedState = YES;
I hope it helps
Upvotes: 5