Scene Control - Help

Scene Control - Help
0.0 0


I have a main menu scene

I have a settings scene

I want to be able translate to settings and then back to main menu.

However, I cannot include the header file in each as causes error

Cannot include mainmenu.h in settings and settings.h in main menu, as its C++ error

What can i do



Show code, please. You should be able to do this just fine.


I had trouble with this before and had make huge changes to project.

When I include each other in each other it causes all visual studio variables to go white and get confused.

Before when i had this object it gave errors, also gives errors now I do believe

Are you sure you can include MainMenu.h in Terminal.h and visa versa ? I read this causes confusion with compilers etc

Showing code will be tire sum, id be best sharing repo

How to transfer SceneA->SceneB->SceneA ? Impossible?

You have circular dependencies. The solution, often, is forward declaration of the class(es) you need, rather than having the circular dependencies.

See this:


What should I do to help. In cocos2d-x framework ? What would you do

I need to create a scene Main menu in terminal to go to terminal

I need to create a scene terminal in main menu to go to main menu

? Thanks


If you want us to help you need to post code.

If you want to do it on your own, review the Wikipedia link above. You probably need to remove .h and then forward declare as class xxx; in headers.


This solution isnt working. I followed the code princible fro shared link and it just isnt correct, which ever way I am doing it

Simple put I need this function in each class

Main Menu Scene

MainMenuScene CLASS	
cocos2d::Scene* terminal = Terminal::createScene();


Terminal Scene CLASS	
cocos2d::Scene* MainMenu = MainMenuScene::createScene();
cocos2d::Director::getInstance()->replaceScene(MainMenu );

The cocos2dx documentation tutorials doesn’t have anything to cover this, but i assume its a C++ problem


I placed this in Terminal Class

#ifndef TERMINAL_H
#define TERMINAL_H

#include "cocos2d.h"

class MainMenuScene;

class Terminal : public cocos2d::Scene

		static cocos2d::Scene* createScene();



		cocos2d::Scene* menu = MainMenuScene::createScene(); // ERROR RED UNDERLINE




It is, nothing to do with Cocos2d-x itself.


Anyone have any ideas of how we do this ? Cant figure it ut. Even tried making a Singleton SceneController but it also suffers same issue.


Why do this here, in a header?


Just testing it in header and trying simply the shared code with you, it has same error when in cpp file


Can you post your files so I can drop them into a new project and see?