我有一个代表椭圆的 SKShape 节点。玩家被放置在基于椭圆 CGPath 的贝塞尔路径的当前点上:
我有两个玩家节点可以执行的操作。玩家可以顺时针或逆时针沿着路径行驶。
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")
玩家沿着适当的路径和方向移动。当我停止其中一个 Action 时:
player.removeActionForKey("ClockwiseRotation")
玩家停在上次移动到的路径上。我希望能够从玩家的当前点开始任何一个 Action ,并遵循相同的路径,但是现在,如果我再次开始其中一个 Action (在 Action 已经开始和停止之后),玩家会跳到图中所示的相同起点,然后从那里沿着路径走。我怎样才能让玩家从它已经在的点开始跟随路径?
最佳答案
您可以使用 SKNode 的 speed
属性轻松实现这一点。
您可以通过调整速度值来暂停和恢复 Action ,而不是删除并重新创建 Action 。这将使您的贝塞尔曲线路径动画从当前位置恢复。
// 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];
关于cocoa-touch - 在不从 CGPath 开始的情况下使用 SKAction 跟随 CGPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24234801/