I am setting up a scene with a fixed background (a simple rectangle), an SKEmitterNode, and a backgroundLayer (a SKNode including many SKShapeNodes) : this is the hierarchy of my scene. But, even if I am adding the emitter node as a child of the scene just after the fixed background and just before the background layer, the particles emitted are at the foreground, which is not what I am expecting. indeed, I would like them to be rendered between the fixed background and the background layer, which is not happening.
I am running this app on ios 10. I've tried to add childs in a different order, or to change the target node, but it didn't change anything...
All of the following code comes from 'init(size: CGSize) {}' of a scene class which inherits from SKScene.This is all the scene set up process (when childs are added).
anchorPoint = CGPoint(x: 0, y: 0)
background.position = CGPoint(x: sceneSize.width / 2, y: sceneSize.height / 2)
background.fillColor = UIColor(white: 0.5, alpha: 1)
background.strokeColor = UIColor.lightGray
addChild(background)
setUpParticleEmitter() // it sets up the particle emitter which is an attribute of the class
addChild(backgroundEmitter) // This is the name of the emitter
backgroundEmitter.targetNode = scene
backgroundLayer.position = CGPoint(x: 0, y: 0)
addChild(backgroundLayer)
gameLayer.position = CGPoint(x: -1 * sceneSize.width, y: 0) // another layer for futur nodes
addChild(gameLayer)
I expect the particles to be rendered between 'background' and 'backgroundLayer', but they are rendered at the foreground (=over the backgroundLayer's childs), is it possible to change that ?
You can chose which nodes to be in front and which in back by setting them the zPosition.
first_node.zPosition = 1
second_node.zPosition = 2 // displayed over first node