SpriteKit:子节点不会与父SKNode一起旋转

时间:2015-04-29 23:30:00

标签: ios swift sprite-kit

目标是使用角速度而不是zRotation围绕点旋转物理主体。因此,似乎需要添加第二个物理体(控制旋转的体),但是改变该父体的角速度不会移动子体。换句话说,父母轮换,但孩子仍然在原地。

如何旋转父母和孩子?

   parent = SKNode()
   sprite = SKSpriteNode(color: SKColor.whiteColor(), size: spriteSize)
   sprite.position = CGPoint(x: 0, y: 50)
   parent.addChild(sprite)

   parent.physicsBody = SKPhysicsBody(rectangleOfSize: parentSize)
   parent.physicsBody?.affectedByGravity = false
   parent.physicsBody?.friction = 0
   parent.physicsBody?.linearDamping = 0
   parent.physicsBody?.angularDamping = 0
   parent.physicsBody?.collisionBitMask = 0

   sprite.physicsBody = SKPhysicsBody(rectangleOfSize: spriteSize)
   sprite.physicsBody?.affectedByGravity = false
   sprite.physicsBody?.friction = 0
   sprite.physicsBody?.linearDamping = 0
   sprite.physicsBody?.angularDamping = 0
   sprite.physicsBody?.categoryBitMask = bitMask
   sprite.physicsBody?.collisionBitMask = 0

   parent.physicsBody?.angularVelocity = 2.0

1 个答案:

答案 0 :(得分:1)

您可以在设置角速度

之前尝试在父级和子级之间创建关节
let fixedJoint = SKPhysicsJointFixed()
fixedJoint.bodyA = parent.physicsBody
fixedJoint.bodyB = sprite.physicsBody
self.physicsWorld.addJoint(fixedJoint)