1

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

代码如下所示:

-(BOOL) ccTouchBegan:(UITouch *)touch 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];
}

}

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

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

1 回答 1

0

在对多个 CCMove* 操作进行排序时,您总是会出现 1 帧延迟。

会发生以下情况:

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

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

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

于 2012-12-14T12:44:45.830 回答