私はトップダウンのタイルベースのゲームを作っています(GameBoyの古いポケモンとゼルダのゲームを考えてください)。キャラクターのスムーズな動きに問題があります。問題は、アクションを終了してから新しいアクションを開始するまでの遅延だと思います。
コードは次のようになります。
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event {CGPoint touchCoor = [自己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]; }