2017-06-21 73 views
2

我正在使用以下代码来使Sprite节点在Xcode spritekit中的圆圈中移动。Sprite节点的起始位置

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()来改变精灵节点的方向,但这不是我所要求的。

如何将“起点”更改为圆形路径的左侧?

谢谢!请参考下面的图:d

Example of Question

+0

[开始的可能的复制和UIBezierPath的结束角度?](https://stackoverflow.com/questions/32165027/start-and-end-angle-of-uibezierpath) –

回答

2

CGPath(ellipseIn:...)是这产生一个椭圆形,其中,“参数”或“角”从0到2π的路径 一个实用程序方法。

不能添加一个“偏移”的后续行动,但你可以定义 的方式的路径,它开始于圆的“左端”:

let circlePath = CGMutablePath() 
circlePath.addArc(center: pathCenterPoint, radius: circleDiameter, 
        startAngle: -.pi, endAngle: .pi, clockwise: false) 
+0

正如Martin所说 - 精灵会在绘制完成后正确地遵循这个补丁。 –

+0

谢谢马丁!我试图“抵消”,但它不起作用。干杯! – Questions