Running an action over several scenes

Here I have a notification asset:

level%20selection%20notification

I want it to regardlessly move in from the side over 4 scenes, how do I ensure that this notification tab will slide in from the side without being affected by the switching of scenes?

you can only have 1 Scene running at a time. If you replace the Scene 1 with Scene 2, you will need to Scene 2 show this again.

Or just use one scene and do all that you want.
For example I use only one scene in my game and I like this more than several scenes because following issue:
I have some animation in scene 1 and switching to scene 2. I reattach animation from previous scene to new one then animation is stopped.

1 Like

oh, I already have 5 scenes. and the level selection consists of 4 scenes

I usually have a minimal amount of scenes in my games. In one of my most recent games I have just 2 scenes and when I go from level 1 to level 2 I just preload everything I need for level 2 towards the end of level 1, remove all the nodes from level 1 and show what I need to start level 2. Technically the user can keep playing from level 1 to level 2 without stopping if they wish.

That is convenient, in future I will be minimal. But do you know any solution tó what I ám trying to achieve? I did hear if something called zlayer but I am just guessing what it’s function is

maybe zorder?

If you need to show something on top just add it to scene on top.

For example scene graph might be:

Scene:
    GameNode
        SomeNode
            SomeNode
    TopMostNode

but he wants it to persist between scene changes…

ah, well i suppose everything has it’s drawbacks :sob:

Example how to reattach topmost node to a new scene:

Scene* scene2 = Scene::create();
topmostNode->retain();
topmostNode->removeFromParent();
// here attach to scene2 your game node
scene2->addChild(topmostNode);
topmostNode->release();
Director::getInstance()->replaceScene(scene2);

Is this complicated?

He wants it to show the entire time is how I read his OP. This doesn’t do that.

If he is OK with the Node being gone between scene changes your solution should work.

Could the pop scene feature help in any way?

My code does this but without scenes transitions.
@anon97208230 do you use scenes transitions?

not between the four scenes, so i will analyse and try to use your code, thank you

wait so this code goes in scene 2’s cpp, and we do not keep the code from topmostNode to (scene2); in curly brackets?

Did not get your question

The code you provided,

Example how to reattach topmost node to a new scene:


Scene* scene2 = Scene::create();
topmostNode->retain();
topmostNode->removeFromParent();
// here attach to scene2 your game node
scene2->addChild(topmostNode);
topmostNode->release();
Director::getInstance()->replaceScene(scene2);

Is this complicated

where do I place this code? Image my notification asset is in a scene called Notif, what cpp do I put the code in and where within the cpp do i put the code?

This code moves topmostNode to new just created scene.
Do this when you need to create new scene (maybe some next level) and you need to display the same topmostNode on it.

here is an example of what I want to achieve, imagine you are doing your business on your computer and from the side a notification slides in then slides out, that’s what I am trying to get to happen. It will set it to occur 4 seconds after a certain scene is opened.

there are 5 scenes playing in this scenario

1- main screen (no notif here)

2-level selection (activate notification scene)

3-level selection (play notification over this IF selected)

4-level selection (play notification over this IF selected)

5-level selection(play notification over this IF selected)

Ok, understood. Do you use any animation for your notif?

If yes then use removeFromParentAndCleanup(false) like this:

Scene* scene2 = Scene::create();
topmostNode->retain();
topmostNode->removeFromParentAndCleanup(false);
// here attach to scene2 your game node
scene2->addChild(topmostNode);
topmostNode->release();
Director::getInstance()->replaceScene(scene2);