Cocos2d iphone CCMenuItemSprite';cocos2dv3中的替代方案

Cocos2d iphone CCMenuItemSprite';cocos2dv3中的替代方案,cocos2d-iphone,Cocos2d Iphone,在COCOS2D2.0中,我使用下面的代码将单个图像用于正常图像和选定图像,并在选择时改变颜色 CCSprite *twitter_1 = [CCSprite spriteWithSpriteFrameName:FRAME_MM_TWR_1]; CCSprite *twitter_2 = [CCSprite spriteWithSpriteFrameName:FRAME_MM_TWR_2]; twitter_2.color = ccc3(128,128,128); CCMenu

在COCOS2D2.0中,我使用下面的代码将单个图像用于正常图像和选定图像,并在选择时改变颜色

CCSprite *twitter_1     = [CCSprite spriteWithSpriteFrameName:FRAME_MM_TWR_1];
CCSprite *twitter_2     = [CCSprite spriteWithSpriteFrameName:FRAME_MM_TWR_2];
twitter_2.color = ccc3(128,128,128);

CCMenuItemSprite *twitterBtn = [CCMenuItemSprite itemWithNormalSprite:twitter_1
                                                       selectedSprite:twitter_2
                                                               target:self
                                                             selector:@selector(twitterBtnPress:) ];
在COCOS2DV3中,我可以使用CCButton作为替代,但如何更改选定的帧颜色

CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];

CCButton * twitterBtn = [CCButton buttonWithTitle:@""
                                     spriteFrame:[cache spriteFrameByName:FRAME_MM_TWR_1]
                          highlightedSpriteFrame:[cache spriteFrameByName:FRAME_MM_TWR_1]
                             disabledSpriteFrame:nil];

twitterBtn = CCPositionTypeNormalized;
twitterBtn.position = ccp(0.5f, 0.5f);
[twitterBtn setTarget:self selector:@selector(playBtnPress:)];
[self addChild: twitterBtn];

现在在Cocos2d v3中,如何使用CCSprite作为按钮并更改颜色?

您可以使用以下方法:

- (void) setBackgroundColor:(CCColor*)color forState:(CCControlState)state

使用CCButton为不同的状态设置不同的背景色。

感谢您的回答,在cocos2d 2.0之前,我们可以使用sprite作为按钮,并可以对所选图像和普通图像执行不同的操作…现在我们做不到。对不起,我不完全理解这个问题。你们能澄清一下吗?就像我想在使用普通精灵和选定精灵之前,按一下按钮缩放图像一样,只缩放选定的图像。现在有没有办法用精灵来做按钮,这样我们就可以在不同的状态下使用动作了?