gpt4 book ai didi

iphone - 在 Cocos2d 中缩放 CCMenuItem (Objective-C)

转载 作者:搜寻专家 更新时间:2023-10-30 19:40:48 24 4
gpt4 key购买 nike

我正在尝试制作一个具有缩放图像的 CCMenuItem。例如,我试过:

CCSprite* normalSprite = [CCSprite spriteWithFile:@"button_play.png"];
CCSprite* selectedSprite = [CCSprite spriteWithFile:@"button_play.png"];
selectedSprite.scale = 1.2;

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

但看起来 CCMenuItemSprite 忽略了底层 Sprite 的比例。有没有办法做到这一点(除了创建基础图像的缩放版本之外)?谢谢。

最佳答案

Thyrgle 关于 CCMenuItem 的工作方式是正确的。

但是,肯定有办法做你想做的事。您需要做的就是子类化 CCMenuItem 并重写选定和未选定的方法来实现您想要的。事实上,我很确定您可以从 CCMenuItemLabel 中剪切和粘贴代码,因为将项目缩放到 1.2 正是它所做的。 (事实上​​ ,它做得更好,因为它动画了比例变化。)

-(void) selected
{
// subclass to change the default action
if(isEnabled_) {
[super selected];
[self stopActionByTag:kZoomActionTag];
CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:1.2f];
zoomAction.tag = kZoomActionTag;
[self runAction:zoomAction];
}
}

-(void) unselected
{
// subclass to change the default action
if(isEnabled_) {
[super unselected];
[self stopActionByTag:kZoomActionTag];
CCAction *zoomAction = [CCScaleTo actionWithDuration:0.1f scale:1.0f];
zoomAction.tag = kZoomActionTag;
[self runAction:zoomAction];
}
}

关于iphone - 在 Cocos2d 中缩放 CCMenuItem (Objective-C),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3081853/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com