我正在製作一個自頂向下的基於瓷磚的遊戲(在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]; }
只是要清楚,做一些事情:onUpdateEvent - if(haventArrived){moveSomeDistance} – InkGolem
此外,是不是可以動態排隊更多的行動?如同在另一個完成之前添加額外的移動動作一樣? – InkGolem