Scene Replacement Problem

Hey Guys! I’m trying to replace a scene with another one. While this is fairly simple, I can’t get it to work.
I’m sure that the function is being called, as it logs the message.

Any help appreciated!

Hi
Try this
auto menuLayer = MenuLayer::createScene();

Hey, Turned out i was using the wrong function, However, this didn’t resolve the problem. The scene still stays the same. :confused:

Who is called LoadingFinished function ?

Are you running in debug or release enviorment ?

A function called loadAssets calls the LoadingFinished function. I’m running in Debug, I’m sure the function is being called, because the log() shows up.

Alright so I think I’m getting somewhere. The code in the init function get’s called, but the textures from the old scene are not being replaced by the new empty scene. :confused:

Post more code. What is menuLayer?

MenuLayer is a scene! Here are the classes:
LoadingLayer.cpp:


MenuLayer.cpp:

I do this very different than you do. It is hard to tell what you are really doing because you aren’t posting the whole class and you are posting screenshots instead of pasting in code.

Alright, Here i’ll provide a pastebin of both the scenes (fully) and my AppDelegate.
AppDelegate.cpp:
https://pastebin.com/vA7ws7Kb
LoadingLayer.cpp:
https://pastebin.com/VBgniZfM
MenuLayer.cpp:
https://pastebin.com/jVZtYtM2

Sorry if this is a bad way of sending the code, couldn’t think of anything better :frowning_face:

You can always upload the .cpp and .h right inside your message.

What version of Cocos2d-x are you using?

  1. There is no need to use Layer. You can just add elements to a Scene directly.

  2. You are using Deprecated class names, like CCTextureCache clean these up.

  3. this:

auto menuLayer = MenuLayer::createScene();
Director::getInstance()->replaceScene(menuLayer);

can just be:

Director::getInstance()->replaceScene(MenuLayer::createScene());
  1. This:
auto scene = Scene::create();

you need to move the declaration to your header file where it makes sense for you…You are failing because you are out of scope. Remember that Cocos2d-x uses an auto-release pool so you need to retain() if you want to keep objects around.

Our docs will help with this.

1 Like

Thank you!