- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 cocos2d 创建一个程序,其中有 2 个 ccMenuItems,每个链接到一个图像:在这种情况下,一个是左箭头,另一个是右箭头。我的 View 中心还有一个图像,它会根据按下的箭头旋转。
当我将手指放在两个菜单项之一(左侧或右侧)上时,我希望只要我的手指在按钮上,中心图像就会旋转。那就是我迷路的地方。我尝试使用以下代码:
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint p = [touch locationInView:[touch view]];
if (CGRectContainsPoint(leftArrow, p) || CGRectContainsPoint(rightArrow, p)) {
return YES;
}
return NO;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint p = [touch locationInView:[touch view]];
if (CGRectContainsPoint(leftArrow, p)) {
[gun runAction:[CCRepeatForever actionWithAction:[CCRotateTo actionWithDuration:0.2 angle:180]]];
}
if (CGRectContainsPoint(rightArrow, p)) {
[gun runAction:[CCRepeatForever actionWithAction:[CCRotateTo actionWithDuration:0.2 angle:0]]];
}
}
使用这段代码,当我按下两个菜单项之一时,甚至都没有调用 ccTouchBegan 方法。仅当我触摸其他地方时才调用该方法。
如何在按住 ccMenuItem 时处理连续 Action 。
感谢您的帮助!
最佳答案
您必须继承 CCMenuItem 才能获得此类行为:
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
@interface RepeatMenuItem : CCMenuItemSprite
{
CGFloat speed;
}
@end
和实现:
////////////////////////////////////////////////////////////////////
// RepeatMenuItem
////////////////////////////////////////////////////////////////////
#pragma mark -
#pragma mark RepeatMenuItem
@implementation RepeatMenuItem
-(void) selected
{
[super selected];
block_(self);
speed = 0.8;
[self schedule:@selector(repeatEvent:) interval:speed];
}
-(void) unselected
{
[self unschedule:@selector(repeatEvent:)];
[super unselected];
}
-(void) activate
{
}
-(void) repeatEvent:(id)sender
{
CGFloat minSpeed = 0.05;
if (speed > minSpeed)
speed = speed/3;
if (speed < minSpeed)
speed = minSpeed;
[self unschedule:@selector(repeatEvent:)];
block_(self);
[self schedule:@selector(repeatEvent:) interval:speed];
}
@end
关于iphone - 连续触摸 ccMenuItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13103501/
是否可以让系统在 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 项目重叠时,最后添加到
我是一名优秀的程序员,十分优秀!