4

我有一个代表椭圆的 SKShape 节点。玩家被放置在基于椭圆的 CGPath 的 Bezier 路径的当前点上:

在此处输入图像描述

我有两个播放器节点可以执行的操作。玩家可以顺时针或逆时针跟随路径。

rotateCounterClockwiseAction = SKAction.followPath(counterClockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)
rotateClockwiseAction = SKAction.followPath(clockwisePath.CGPath, asOffset: false, orientToPath: true, duration: 1)

当我开始其中一项操作时:

player.runAction(SKAction.repeatActionForever(rotateClockwiseAction), withKey: "ClockwiseRotation")

玩家沿着适当的路径和方向移动。当我停止其中一项操作时:

player.removeActionForKey("ClockwiseRotation")

玩家停在最后一次移动到的路径上。我希望能够从玩家的当前点开始任何一个动作,并遵循相同的路径,但是现在,如果我再次开始其中一个动作(在一个动作已经开始和停止之后),玩家会跳跃到与图片中相同的起点,然后从那里沿着路径前进。我怎样才能让玩家从它已经在的位置跟随路径?

4

1 回答 1

0

speed您可以通过使用SKNode的属性轻松实现此目的。

您可以通过调整速度值暂停和恢复动作,而不是删除和重新创建动作。这将导致您的贝塞尔路径动画从其当前位置恢复。

// Set the player node's speed to 0.0 causing all actions to be paused.
[playerNode setSpeed:0.0];

...

// Then when you're ready to resume set the player node's speed back to 1.0.
// This will cause the action to continue from its current position.
[playerNode setSpeed:1.0];
于 2014-06-23T15:24:01.233 回答