我目前正在精灵节点上运行以下代码。
// the circle path's diameter
let circleDiameter = CGFloat(150)
// center our path based on our sprites initial position
let pathCenterPoint = CGPoint(
x: player.position.x - circleDiameter/2,
y: player.position.y - circleDiameter/2
)
// create the path our sprite will travel along
let circlePath = CGPath(ellipseIn: CGRect(origin: pathCenterPoint, size: CGSize(width: circleDiameter, height: circleDiameter)), transform: nil)
// create a followPath action for our sprite
let followCirclePath = SKAction.follow(circlePath, asOffset: false, orientToPath: true, duration: 4)
// make our sprite run this action forever
player.run(SKAction.repeatForever(followCirclePath))
self.addChild(player)
目前代码工作正常,但是播放器在圆形路径中移动时会旋转。无论如何,我可以阻止玩家精灵旋转,因为它在圆圈中移动?
干杯:D
您
需要做的就是更改此行:
let followCirclePath = SKAction.follow(circlePath, asOffset: false, orientToPath: true, duration: 4)
对此:
let followCirclePath = SKAction.follow(circlePath, asOffset: false, orientToPath: false, duration: 4)
只需将 orientToPath 设置为 false。
作为参考,Apple 在以下文档中对此进行了记录:https://developer.apple.com/reference/spritekit/skaction/1417798-follow