2012-12-14 42 views
1

我正在制作一个自顶向下的基于瓷砖的游戏(在GameBoy上考虑老的口袋妖怪和塞尔达游戏)。我在角色移动过程中遇到问题。我认为问题在于完成一项行动和开始一项新行动之间的延迟。Cocos2d - 角色似乎是口吃步进

下面的代码是什么样子:

- (BOOL)ccTouchBegan:(UITouch *)触摸withEvent:方法(*的UIEvent)事件{ CGPoint touchCoor = [自我coordinateForTouch:触摸]。

// 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; 

}

//给定在屏幕尺寸点 //对所有运动 基座运动功能 - (无效)movePlayer:(的NSString *)PID toPosition:(CGPoint)位置{ 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]; }

回答

0

当您对多个CCMove *动作进行排序时,您总是会得到1帧的延迟。

所发生的是以下内容:

  • 帧0-100:移动动作运行时,子画面移动
  • 框架101:移动动作结束时,运行CCCallFunc
  • 框架102:新的移动动作开始

这种一帧延迟是排序移动操作的主要问题之一,也是我不推荐使用移动操作进行游戏操作的原因之一。

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

+0

只是要清楚,做一些事情:onUpdateEvent - if(haventArrived){moveSomeDistance} – InkGolem

+0

此外,是不是可以动态排队更多的行动?如同在另一个完成之前添加额外的移动动作一样? – InkGolem