我有两个要相互连接的 SKShapeNode 节点。当我点击执行一个动作时,我希望两个节点扩大它们的高度,再次点击时我希望它们缩回。问题是两个节点没有按预期动画:
动画前:(未展开)
动画后:(展开)
两个节点都在扩展,但似乎一个正在另一个之下。我想要发生的是他们互相“推开”。
override func didMoveToView(view: SKView) {
let size = CGSize(width: view.frame.width, height: 100)
let firstSection = SKShapeNode(rectOfSize: size)
firstSection.physicsBody = SKPhysicsBody(rectangleOfSize: size)
firstSection.fillColor = SKColor.purpleColor()
firstSection.physicsBody?.affectedByGravity = false
firstSection.position = CGPoint(x: 500, y: 400)
firstSection.name = "section"
self.addChild(firstSection)
let secondSection = SKShapeNode(rectOfSize: size)
secondSection.fillColor = SKColor.blueColor()
secondSection.physicsBody = SKPhysicsBody(rectangleOfSize: size)
secondSection.physicsBody?.affectedByGravity = false
secondSection.position = CGPoint(x: 500, y: 300)
secondSection.name = "section"
self.addChild(secondSection)
let joint = SKPhysicsJointSpring.jointWithBodyA(firstSection.physicsBody, bodyB: secondSection.physicsBody, anchorA: firstSection.position, anchorB: secondSection.position)
self.physicsWorld.addJoint(joint)
}