3
votes

I am making a small game using swift and sprite kit.

In my GameScene.sks I have created two color sprites: one called "Parent" which is a child of SceneNode and one called "Child" which is a child of "Parent". The texture of "Parent" is a .png image from my xcassets, the child node is just a green color sprite.

Now the curious thing is that when I build and run the application, the parent node is somehow drawn in front of the child node (which is clear when I place the two nodes partially overlapping).

I have tried to make both nodes have a single color or give both nodes a custom texture, and in both cases this solves the issue: the child is drawn in front of the parent.

2
you should post some codes so that others can help. - warunapww

2 Answers

2
votes

To draw your child node behind your parent node, set the zPosition of the childNode to be higher than that of the parentNode.

2
votes

To draw the child node BEHIND parent, its zPosition must be smaller than the parent's. E.g. if you are adding a node in the parent node's class, use this:

[self addChild:childNode];
childNode = self.zPosition - 1;