Sprite沿着UIBezierPath移动,如何从Sprite位置反转方向

时间:2015-09-16 21:35:45

标签: swift sprite-kit

现在已经有一段时间了。我有Sprite,一旦触摸屏幕,它就会沿着UIBezierPath逆时针移动。我也有它,所以它沿着UIBezierPath反转方向,但它总是回到路径的开头。我希望Sprite反转方向,但从sprite的位置开始。这是我的所有代码,非常感谢任何帮助!

如果您有任何其他问题,请随时提出。 :)

var Circle = SKSpriteNode()
var Person = SKSpriteNode()
var Path = UIBezierPath()

var gameStarted = Bool()
var clockWise = true

override func didMoveToView(view: SKView) {
    Circle = SKSpriteNode(imageNamed: "Circle")
    Circle.size = CGSize(width: 300, height: 300)
    Circle.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))
    self.addChild(Circle)

    Person = SKSpriteNode(imageNamed: "Person")
    Person.size = CGSize(width: 40, height: 7)
    Person.position = CGPoint(x: self.frame.size.width / 2, y: self.frame.size.height / 2 + 112)
    Person.zRotation = 3.14 / 2
    self.addChild(Person)


    Path = UIBezierPath(roundedRect: CGRect(x: self.frame.width / 2 - 113 , y: self.frame.height / 2 - 113, width: 226, height: 226), cornerRadius:226)


}


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
   /* Called when a touch begins */


    let follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 100)
    NSLog("\(self.frame.width / 2 - Person.position.x)")
     NSLog("\(self.frame.height / 2 - Person.position.y)")

    if gameStarted == false{
        gameStarted = true
        let Follow = SKAction.followPath(Path.CGPath, asOffset: false, orientToPath: true, speed: 100)
        Person.runAction(SKAction.repeatActionForever(follow))
        clockWise = false
    }

    else if gameStarted == true{
        if clockWise == true{
            clockWise = false
            Person.runAction(SKAction.repeatActionForever(follow))
        }
        else if clockWise == false{
            clockWise = true
            Person.runAction(SKAction.repeatActionForever(follow).reversedAction())
            //NSLog("\(Path.description)")
        }

    }



}

0 个答案:

没有答案