精灵套件 - 旋转以面向地面

时间:2014-06-20 15:24:07

标签: ios sprite-kit swift

我做了一个精灵站在地上,但我希望精灵旋转到地面,这样看起来就像是在地上爬行。

func setUpRunner() {
    let runnerSize = CGSizeMake(15, 40)
    Runner = SKShapeNode(rectOfSize: runnerSize)
    Runner.fillColor = SKColor.blackColor()
    Runner.name = self.rName

    Runner.physicsBody = SKPhysicsBody(rectangleOfSize: runnerSize)
    Runner.physicsBody.dynamic = true
    Runner.physicsBody.affectedByGravity = true
    Runner.physicsBody.allowsRotation = false
    Runner.physicsBody.restitution = 0.0
    Runner.physicsBody.categoryBitMask = rCategory
    Runner.physicsBody.contactTestBitMask = groundCategory

    Runner.position = CGPointMake(20, self.frame.height/3)
    self.addChild(Runner)
}

func crouch() {
    Runner.zRotation = 90 //or -90
}

但这会使他面对东北,西北。

1 个答案:

答案 0 :(得分:1)

查看SKNode的API。它说

zRotation
The Euler rotation about the z axis (in radians).

这意味着360度为2*M_PI,因此90度为M_PI/2