I want to create a constant Layer that is not affected by the replaceScene(scene); method.
so I have something like this (obviously )
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?
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.
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 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? Never used the notificationNode
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.
Iām using cocos2dx ver. 3.4 Iām upgrading now to cocos 3.10 and will let You know if it works However now Iām getting some _iconv undefined symbol errors
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