Swift 当精灵在圆形路径上移动时停止旋转?
我目前正在一个sprite节点上运行以下代码Swift 当精灵在圆形路径上移动时停止旋转?,swift,sprite-kit,Swift,Sprite Kit,我目前正在一个sprite节点上运行以下代码 // 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: pl
// 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
苹果公司在以下文件中对此进行了记录,以供参考:
面部手掌谢谢!现在效果很好:D也为参考欢呼!我去看看!