为什么我的SKSpriteNode在重复动画期间会慢慢移动到屏幕的右上角?

时间:2015-12-30 16:46:55

标签: ios swift sprite-kit core-graphics

我的spriteNode正慢慢移动到我的SKScene的右上角。我注意到更改didMoveToView(..)中操作的计时模式可能会导致方向更改。是什么导致了这种行为,我该如何解决?

override func didMoveToView(view: SKView) {

   let spriteNode = self.childNodeWithName("character") as! SKSpriteNode

    spriteNode.zRotation = CGFloat((M_PI / 2) / 1.3)

    let rotation1 = SKAction.rotateByAngle(CGFloat((-M_PI / 2)), duration: 1)
    rotation1.timingMode = SKActionTimingMode.EaseOut

    let rotation2 = rotation1.reversedAction()
    rotation2.duration = 0.4
    rotation2.timingMode = SKActionTimingMode.Linear

    let path = self.generatePath1()
    let movement1 = SKAction.followPath(path, asOffset: true, orientToPath: false, duration: 1)
    movement1.timingMode = SKActionTimingMode.EaseOut

    let movement2 = movement1.reversedAction()
    movement2.duration = 0.4
    movement1.timingMode = SKActionTimingMode.Linear

    let rotations = SKAction.sequence([rotation1, rotation2])
    spriteNode.runAction(SKAction.repeatActionForever(rotations))

    let movements = SKAction.sequence([movement1, movement2])
    spriteNode.runAction(SKAction.repeatActionForever(movements)
}

func generatePath1() -> CGPathRef {
        var bezierPath = UIBezierPath()
        bezierPath.moveToPoint(CGPointMake(0, 0))
        bezierPath.addCurveToPoint(CGPointMake(30, 50), controlPoint1: CGPointMake(30, 50), controlPoint2: CGPointMake(20, 40))

        return bezierPath.CGPath
    }

0 个答案:

没有答案