【发布时间】:2014-04-23 15:08:24
【问题描述】:
我在执行操作时无法暂时禁用触摸交互。当前,当我向上滑动时,我的角色会进行跳跃翻转,但是如果您立即再次向上滑动,它会再次翻转。我想在执行操作时禁用任何交互。
我有以下代码调用“开始”函数,假设暂时禁用触摸,以及在动作完成后重新启用触摸交互的“结束”函数,所有这些都在 ccactionspawn 中,但它不工作。
-(void)begin
{
[[UIApplication sharedApplication]beginIgnoringInteractionEvents];
}
-(void)end
{
[[UIApplication sharedApplication]endIgnoringInteractionEvents];
}
-(void)jump
{
CCActionRotateBy* flip = [CCActionRotateBy actionWithDuration:0.8f angle:360];
CCActionJumpBy* jump = [CCActionJumpBy actionWithDuration:0.8f position:CGPointMake(150, 0) height:130 jumps:1];
CCAction *actionMove = [CCActionMoveTo actionWithDuration:1.0f position:CGPointMake(-_character.contentSize.width/2, self.contentSize.height/4)];
CCActionSpawn *flipJump = [CCActionSpawn actions:[CCActionCallFunc actionWithTarget:self selector:@selector(begin)], jump, flip, actionMove, [CCActionCallFunc actionWithTarget:self selector:@selector(end)], nil];
[_character runAction:flipJump];
}
感谢您的帮助!
-使用工作代码进行编辑。
感谢所有的帮助家伙!如果有人需要,这是我的工作代码:
-(void)begin
{
self.userInteractionEnabled = FALSE;
}
-(void)end
{
self.userInteractionEnabled = TRUE;
}
-(void) touchBegan:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLoc1 = [touch locationInNode:self];
firstTouch = touchLoc1;
CCLOG(@"touched");
}
-(void) touchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
CGPoint touchLoc2 = [touch locationInNode:self];
lastTouch = touchLoc2;
//Minimum length of the swipe
float swipeLength = ccpDistance(firstTouch, lastTouch);
//Check if the swipe is an up swipe and long enough
if (firstTouch.y < lastTouch.y && swipeLength > 10) {
CCActionRotateBy* flip = [CCActionRotateBy actionWithDuration:0.8f angle:360];
CCActionJumpBy* jump = [CCActionJumpBy actionWithDuration:0.8f position:CGPointMake(150, 0) height:130 jumps:1];
CCAction *actionMove = [CCActionMoveTo actionWithDuration:1.0f position:CGPointMake(-_character.contentSize.width/2, self.contentSize.height/4)];
CCActionSequence *flipJump = [CCActionSequence actions:[CCActionCallFunc actionWithTarget:self selector:@selector(begin)], flip, actionMove, [CCActionCallFunc actionWithTarget:self selector:@selector(end)], nil];
[_character runAction:jump];
[_character runAction:flipJump];
}
}
【问题讨论】:
标签: ios cocos2d-iphone