I have a wrapper class to create a label node with some subnodes. This is the init for the class:
let label = SKLabelNode(text: word)
let background = SKShapeNode(rectOfSize: size, cornerRadius: 0.5)
let mainNode = SKSpriteNode(color: color, size: background.frame.size)
label.horizontalAlignmentMode = SKLabelHorizontalAlignmentMode.Center
label.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
label.addChild(background)
label.addChild(mainNode)
mainNode.zPosition = 1
background.zPosition = 2
label.zPosition = 5
self.node = label
In my main scene I instantiate the node, set its physics body and set the gravity for the scene:
self.physicsWorld.gravity = CGVectorMake( 0, -10 );
let node = MyNode()
node.node.zPosition = 99
node.node.position.y = endOfScreenTop
if let name = node.node.name as String!, let sprite = node.node.childNodeWithName(name) as? SKSpriteNode {
node.node.physicsBody = SKPhysicsBody(rectangleOfSize: sprite.size)
node.node.physicsBody!.mass = 1.0;
node.node.physicsBody!.angularDamping = 0.0;
node.node.physicsBody!.linearDamping = 0.0;
node.node.physicsBody!.friction = 0.0;
node.node.physicsBody!.affectedByGravity = true
node.node.physicsBody!.dynamic = true
node.node.physicsBody!.allowsRotation = false
}
addChild(node.node)
I have 2 problems:
- The label appears behind the SKSpriteNode, even though the zPosition should place it at the front
- The SKShapeNode (that's just an insets to smooth the corners) doesn't appear at all
- None of the nodes are affected by gravity
PS. Even changing the following to true doesn't change anything:
skView.ignoresSiblingOrder = false
PS2. the MyNode class has these properties
var node: SKLabelNode
var speed: CGFloat = 1.0
var word: String
var color: UIColor
var kind: Kind