I'm using Swift and Sprite Kit. I have an SKNode
called MrNode
that has several SKSpriteNodes
and SKNode
child nodes. Some of the SKNode
s have children that have children of their own as well. To reference them, I do the following
var MrNode = SKNode?()
override func didMoveToView(view: SKView)
{
MrNode = childNodeWithName("MrNode")
}
func DimLights()
{
let liftmotor1:SKNode = MrNode!.childNodeWithName("LiftMotor1")!
let liftPlatform1:SKSpriteNode = liftmotor1.childNodeWithName("LiftPlatform")as! SKSpriteNode
let light1:SKSpriteNode = liftPlatform1.childNodeWithName("light1")as! SKSpriteNode
let light2:SKSpriteNode = liftPlatform1.childNodeWithName("light2")as! SKSpriteNode
light1.alpha = 0.2
light1.alpha = 0.2
}
To find a SKSpriteNodes
that is a child of child of a child of a child, I call DimLights()
. Is this the best way to do this or is there something better?