0

我一直在按照教程创建基于图块的地图并让角色四处移动。然后我按照教程为运动添加精灵动画。我想出了类似以下的运动:

[self stopAction: cameraMoveAction];
[playerSprite stopAction:playerMoveAction];
[playerSprite runAction: targetAction];

self.playerMoveAction = [CCSequence actions:
                         [CCMoveTo actionWithDuration: MOVEMENT_SPEED * 4 position: newPosition],
                         [CCCallFunc actionWithTarget: self selector: @selector(finishedMoving)],
                         nil
                         ];

self.cameraMoveAction = [CCSequence actions:
                         [CCMoveTo actionWithDuration: MOVEMENT_SPEED * 4 position: [self calculateNewCenterOfScreen: newPosition]],
                         nil
                         ];

[self runAction: cameraMoveAction];
[playerSprite runAction: playerMoveAction];

所以如果你看到了,我正在移动玩家和相机(为了让玩家始终居中)。我也曾尝试在finishedMoving通话中将摄像头对准玩家,但这看起来很糟糕(玩家会移动,然后摄像头会猛拉到玩家的位置)。

有没有更好的方法来做到这一点?

4

1 回答 1

1

您还可以尝试自动跟随给定节点的 CCFollow 操作。当你移动你的播放器时,只需调用类似的东西,

[层runAction:[CCFollow actionWithTarget:playerNode]];

于 2012-08-26T10:46:59.257 回答