[英]Sprite Kit - Rotate to face the ground
我做了一个精灵,站在地面上,但是我想让精灵旋转以面对地面,这样看起来好像他在地面上爬行。
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
}
但这会让他面对东北,西北。
看看SKNode的API。 它说
zRotation
The Euler rotation about the z axis (in radians).
这意味着360度是2*M_PI
,因此90度是M_PI/2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.