我目前正在精灵节点上运行以下代码。
// 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
答案 0 :(得分:0)
您需要做的就是更改此行:
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