- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试制作一个具有缩放图像的 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/
是否可以让系统在 CCMenuItem 元素上移动时调用 ccLayer 的 ccTouchesBegan 而无需覆盖 CCMenuItem 类? 最佳答案 将目标委托(delegate)添加到触摸优
情况: 使用 cocos2d 的 CCMenuItem 和 CCMenu 类,我按以下方式创建菜单。 问题: 菜单项居中对齐。我希望它们左对齐(意思是说每个项目的第一个字母的 x 坐标大致相同) 问题
我正在使用 cocos2d 创建一个程序,其中有 2 个 ccMenuItems,每个链接到一个图像:在这种情况下,一个是左箭头,另一个是右箭头。我的 View 中心还有一个图像,它会根据按下的箭头旋
我有一个包含 5 个 CCMenuItem 的 CCMenu。当用户触摸菜单项时,我希望菜单项向右移动 10 个像素,以区别于其他菜单项。我试着让每个菜单项成为一个全局变量,这样我就可以说: if (
block 引用 我有一个 CCMenuItem 按钮,我希望能够按下该按钮,然后在按下的同时,将创建一个新的 CCSprite ,可以在按下时将其拖走仍然使用相同的压力机。基本上,您按下按钮并拖出一
当我尝试在 iTouch 5 上构建和运行我的游戏(基于 Cocos2d 1.0.1,内置于带有 iOS 6.0 SDK 的 Xcode 4.5 中)时,我发现 CCMenuItems 行为不正常:当
我如何调整 CCMenuItemSprite 以仅支持一个 Sprite ? 目前我有: [CCMenuItemSprite itemWithNormalSprite:one selectedSpri
我开始学习 cocos2d-x,但在创建 CCMenuItem 时出现奇怪的错误 这是我的代码 CCMenuItem *StartMenuItem = CCMenuItemImage::create(
我想在调用 CCMenuItemSprite 的“selected”方法时调用目标选择器(见下文:buttonPressedWithId:)。 CCMenuItemSprite *buttonB =
我在下面创建了这段代码以在 init 语句的 View 中显示一个按钮: CCMenuItem *contacts = [CCMenuItemImage
我正在尝试制作一个具有缩放图像的 CCMenuItem。例如,我试过: CCSprite* normalSprite = [CCSprite spriteWithFile:@"button_play.
我遇到了 CCMenu 和 CCMenuItem 的一个奇怪的怪癖,它们可能是也可能不是 cocos2d 库的一部分,所以我不确定是否应该将其报告为错误。 当两个 CCMenu 项目重叠时,最后添加到
我是一名优秀的程序员,十分优秀!