Sprite 节点的起始位置
Starting position of a Sprite Node
我正在使用以下代码使精灵节点在 Xcode spritekit 中绕圈移动。
let circleDiameter = CGFloat(100)
// center our path based on our sprites initial position
let pathCenterPoint = CGPoint(
x: object.position.x - circleDiameter,
y: object.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: false, duration: 3)
// make our sprite run this action forever
object.run(SKAction.repeatForever(followCirclePath).reversed(), withKey: “moving”)
world.addChild(object)
问题是,精灵节点的起始位置总是位于圆形路径的右侧。我知道我可以使用 .reversed() 来改变精灵节点的方向,但这不是我要问的。
如何将 "starting point" 更改为圆形路径的左侧?
谢谢大家!请参考下图:D
CGPath(ellipseIn:...)
是一种创建路径的实用方法
椭圆的,其中 "argument" 或 "angle" 从 0 到 2π。
您不能将 "offset" 添加到跟随操作中,但您可以定义
路径从圆的 "left end" 开始:
let circlePath = CGMutablePath()
circlePath.addArc(center: pathCenterPoint, radius: circleDiameter,
startAngle: -.pi, endAngle: .pi, clockwise: false)
我正在使用以下代码使精灵节点在 Xcode spritekit 中绕圈移动。
let circleDiameter = CGFloat(100)
// center our path based on our sprites initial position
let pathCenterPoint = CGPoint(
x: object.position.x - circleDiameter,
y: object.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: false, duration: 3)
// make our sprite run this action forever
object.run(SKAction.repeatForever(followCirclePath).reversed(), withKey: “moving”)
world.addChild(object)
问题是,精灵节点的起始位置总是位于圆形路径的右侧。我知道我可以使用 .reversed() 来改变精灵节点的方向,但这不是我要问的。
如何将 "starting point" 更改为圆形路径的左侧?
谢谢大家!请参考下图:D
CGPath(ellipseIn:...)
是一种创建路径的实用方法
椭圆的,其中 "argument" 或 "angle" 从 0 到 2π。
您不能将 "offset" 添加到跟随操作中,但您可以定义 路径从圆的 "left end" 开始:
let circlePath = CGMutablePath()
circlePath.addArc(center: pathCenterPoint, radius: circleDiameter,
startAngle: -.pi, endAngle: .pi, clockwise: false)