开发者

Flip CCMenuItemImage?

开发者 https://www.devze.com 2023-04-05 11:24 出处:网络
In 开发者_JAVA技巧Cocos2d, I can use the flipX property on CCSprites. But I don\'t seem to be able to do it with CCMenuItemImages... is it possible? Or do I have to use an already flipped image resour

In 开发者_JAVA技巧Cocos2d, I can use the flipX property on CCSprites. But I don't seem to be able to do it with CCMenuItemImages... is it possible? Or do I have to use an already flipped image resource?


you cant flip the image that is added to the CCMenuItemImage. I would recommend using CCMenuItemSprite instead. In that case you can easily get the sprite added to the CCMenuItemSprite and flip it:

CCMenuItemSprite *menuItem = [CCMenuItemSprite itemFromNormalSprite:normalSprite selectedSprite:selectedSprite target:self selector:@selector(aSelector)];

then when you want to access the sprite:

CCSprite *someSprite = [menuItem normalImage];
[someSprite flipX];

hope this helps


KDaker had the right idea, but the implementation wasn't quite right. Here is the code that I got to work:

CCSprite *normalSprite = [CCSprite spriteWithFile:@"yourNormalButton.png"];
CCSprite *selectedSprite = [CCSprite spriteWithFile:@"yourSelectedButton.png"];
normalSprite.flipX = TRUE;
selectedSprite.flipX = TRUE;

CCMenuItemSprite *menuItem = [CCMenuItemSprite itemFromNormalSprite:normalSprite selectedSprite:selectedSprite target:self selector:@selector(aSelector)];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号