Cocos2d - 角色似乎是口吃踩踏

时间:2012-12-14 03:28:42

标签: iphone ios cocos2d-iphone

我正在制作一款自上而下的平铺游戏(想想GameBoy上的旧口袋妖怪和塞尔达游戏)。我遇到了角色顺利移动的问题。我认为问题在于完成一个动作和开始一个新动作之间的延迟。

这是代码的样子:

- (BOOL)ccTouchBegan :( UITouch *)触及withEvent:(UIEvent *)event {     CGPoint touchCoor = [self coordinateForTouch:touch];

// If the character was touched, open their dialogue
if (CGPointEqualToPoint(touchCoor, ebplayer.coordinate)) {
    [[CCDirector sharedDirector] replaceScene:
     [CCTransitionMoveInR transitionWithDuration:1.0 scene:[HelloWorldLayer scene]]];
}
else // otherwise, move the character
{
    activeTouch = [self directionForPoint:[touch locationInView:[touch view]]];
    [self movePlayer:nil inDirection:activeTouch];
}

return YES;

}

//在屏幕尺寸点中给出 //是所有运动的基本运动功能 - (void)movePlayer:(NSString *)pid toPosition:(CGPoint)position {     CGPoint playerCoordinate = [self coordinateForPositionPoint:position];

// if we're not already moving, and we can move, then move
if(!isAnimating && [self coordinateIsOnMap:playerCoordinate] && [self isPassable:playerCoordinate]){
    id doneAction = [CCCallFuncN actionWithTarget:self selector:@selector(finishedAnimating)];
    id moveAction = [CCMoveTo actionWithDuration:WALK_DURATION position:position];
    id animAction = [CCAnimate actionWithAnimation: [ebplayer animateDirection:activeTouch withDuration:WALK_DURATION]];
    id walkAndMove = [CCSpawn actionOne:moveAction two:animAction];
    id action = [CCSequence actions: walkAndMove, doneAction, nil];
    isAnimating = YES;
    [player runAction:action];

    ebplayer.coordinate = playerCoordinate;
    [self setViewpointCenter:position Animated:YES];
}

// if it's not passable, just run the animation
if(!isAnimating){
    id doneAction = [CCCallFuncN actionWithTarget:self selector:@selector(finishedAnimating)];
    id animAction = [CCAnimate actionWithAnimation: [ebplayer animateDirection:activeTouch withDuration:WALK_DURATION]];
    id action = [CCSequence actions: animAction, doneAction, nil];
    isAnimating = YES;
    [player runAction: action];
}

}

然后当该操作完成后,尝试再次启动它:

  • (无效)finishedAnimating { isAnimating = NO; [self movePlayer:nil inDirection:activeTouch]; }

1 个答案:

答案 0 :(得分:0)

在对多个CCMove *操作进行排序时,您将始终以1帧延迟结束。

以下是:

  • 第0-100帧:移动动作运行,精灵正在移动
  • 第101帧:移动动作结束,CCCallFunc运行
  • 第102帧:新的行动开始

这种单帧延迟是对移动动作进行排序的主要问题之一,也是我不建议将移动动作用于游戏目的的原因。

另一种方法是通过修改其位置,在预定的更新方法中手动移动对象。您可以使用CCMove *操作代码作为基础。