Can I make an Overlay that is not affected by replace scene?

Hello!

I want to create a constant Layer that is not affected by the replaceScene(scene); method.

so I have something like this (obviously :stuck_out_tongue: )

class Curtains : public cocos2d::Layer
{
  //lots of code
}

I add it to each scene and it looks ok, but when I replace the scene with

auto fadeScene = TransitionSlideInR::create(0.5f, scene);

It naturally moves with the scene as the sceneā€™s change. However I want it to stay there all the time.

Basically what I want to achieve is something like this:

The curtains should stay all the time at the same place and only the ā€œinsideā€ of the scene should move from right to left.
How could I achieve that? Is it possible?

I am not sure this is possible. Layer objects are added to Scene objects. If you get rid of the Scene, everything that is part of it goes with it.

However, thinking outside the box, Why not just use one Scene and instead of switching Scene objects can you just use Layer objects to accomplish it? Perhaps with Actions and setVisible() you can get the effects you are looking for?

1 Like

I think, you could use Director::setNotificationNode().

Director::getInstance()->setNotificationNode(YourOverlayScene::createScene());

BUT: There seems to be a small problem with this on Mac. Director doesnā€™t exit _notificationNode before releasing it in Director::reset() so you should definitely remove it before you exit your game.

Just set it to nullptr again.

Director::getInstance()->setNotificationNode(nullptr);
1 Like

Isnā€™t this used so that one object can get updated every frame?

Honestly, I donā€™t know, whether this is a good idea, but itā€™s workingā€¦
Obviously _notificationNode wasnā€™t implemented to be used this way.
Maybe the developer could comment this.

Quite frankly, I myself would rather implement the solution @slackmoehrle suggested. (But maybe thatā€™s only because Iā€™m already using a single scene approach in my projects because the transition mechanism is kind of limiting for my use cases)

@slackmoehrle
Theoretically I could move to having 1 scene and switching between Layers but atm I have to much code and this would take to much time :confused: However I have one question that is bothering me for a long time now.
Lets say I have 1 Scene and 10 Layers waiting on the right for their turn to come on the scene. Like in this picture:

How would it look from the performance side? The Layers are not in the screen view (only 1 at a time can be visible - the one thats on the scene) but still at the beginning cocos would load ALL the assets from all 10 Layers right? And how is cocos handling sprites that are not visible? Is he using some sort of culling for optimization? So, sprites that are not visible donā€™t harm the performance?

@mausmausgames
Thanks! I will take a look at it! You say that there is a problem on Mac but if the game will be only on iPads and Android tablets then there is no problem? :stuck_out_tongue: Never used the notificationNode :wink:

Well, you could load layers later on. Say you load the first 2, then once the player makes it to 2 you load 3 in the background. Then once they make it to 3, you load 4, etc. I know our render does auto culling. The low level details, I donā€™t know. I am happy to have someone answer specific questions if you have them.

1 Like

@slackmoehrle
Thanks for the answer! :smile:

@mausmausgames @slackmoehrle
Is it possible that actions dont run on the notification node? If so is there a walk around?

Which actions do you have problems with?
I tested a FadeOut action and it worked.
Could you post some code please?

1 Like

@mausmausgames
I found this:

Iā€™m using cocos2dx ver. 3.4 Iā€™m upgrading now to cocos 3.10 and will let You know if it works :wink: However now Iā€™m getting some _iconv undefined symbol errors :frowning:

EDIT:

Upgraded to cocos 3.10 and now the actions run as they should!
So if anyone has this problem in the future just upgrade Your cocos version to at least 3.9 :wink: