Placing background node covers all other nodes level transition

121 views Asked by At

When the game changes levels I have a method that loads a new background and also changes several global properties of the SKScene ie enemy speed etc. Problem is when I redraw the background in a new level it covers all other nodes (created in initWithSize) . Is there a work around or a better approach redrawing the background?

1

There are 1 answers

2
Mobile Ben On BEST ANSWER

If I understand what you are saying you have a level which has a background node and other nodes that are displayed during the level. When you change levels, you add a new background, presumably as a child of SKScene, correct?

If this is the case, that is why it covers everything. By adding it later onto the node tree, it gets drawn last, and hence covers everything.

There are a few ways you can handle this:

-Have a different scene per level. This way each scene is self contained and will not interfere with the other scene's contents.

-removeAllChildren on the SKScene, and then add your background and anything else you need for the new level.

-If you really wanted to, you could just replace the texture for the original background with the newer background. But if you do this, you still potentially need to clean up old nodes.

Having a different scene is probably the better option out of the bunch.