如何在Cocos2d 3.0中设置切换按钮?

Ren*_*iya 1 cocos2d-iphone ios

CCMenu,CCMenuItem,CCMenuItemToggle切换在Cocos2d 3.0中已弃用.我想在cocos2d 3.0中设置切换按钮.

我在3.0中找到了下面的方法但它不起作用.

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];
Run Code Online (Sandbox Code Playgroud)

请帮帮我...先谢谢你...

Fel*_*rdo 5

所以我假设您需要一个切换按钮来启用/禁用声音.

只能通过一个按钮具有两种状态来执行此操作:声音启用(未选中)和声音禁用(选定).

试试这个,也许你仍然需要在处于选定状态时更改一些参数:

CCButton *soundTriggerBtn = [CCButton buttonWithTitle:@""
                        spriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOn.png"]
             highlightedSpriteFrame:[CCSpriteFrame frameWithImageNamed:@"soundOff.png"]
                disabledSpriteFrame:nil];

soundTriggerBtn.togglesSelectedState = YES;
Run Code Online (Sandbox Code Playgroud)

我希望它有所帮助