I have two SKShapeNode nodes that I want to be attached to each other. When I tap to perform an action I want the two nodes to expand their height and upon tapping again I want them to retract. The problem is that the two nodes aren't animating as expected:
Before animation: (unexpanded)
After animation: (expanded)
Both nodes are expanding but it appears that one is going under the other. What I would want to happen is that they "push" each other away.
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)
}