2

I am working on a Cocos2D-X project. I am trying to organize my code files into sub-folders inside the Classes folder. The Classes folder is being shared for both iOS and Android. If I just leave the code files in the Classes folder everything works fine but if I place them into sub-folders I get all types of errors. I've linked the sub-folders in my Project Properties and even added the sub-folders in the Android.mk file but no luck.

I've been Googling/Reading articles and everywhere it keeps saying that you have to keep all classes in the root 'Classes folder'. FOr small projects that might not be an issue but as the project gets bigger it will become a nightmare having to always run through one folder full of all the code files.

Could someone please advise if there is a way to organize .h/.cpp files into sub-folders in Cocos2D-X project.

1
  • You should post your errors with an example of your directory structure. One thing that comes to mind is that XCode is very lenient with paths, but others environments, not so much, so if you include files from other directories you may need the #include "../othersubdir/header.h" or #include "subdir/header.h". Commented Jun 6, 2013 at 15:54

3 Answers 3

1

If you add sub-folders, you should also add them to the #include directives.

For example, if your directory is like this:

+ Classes/
| + HomeScreen/
| | - HomeScreen.cpp
| | - HomeScreen.h
| + GameScreen/
| | - GameScreen.cpp
| | - HomeScreen.h

Your #includes should look like:

#include "HomeScreen/HomeScreen.h"
#include "GameScreen/GameScreen.h"

Of course, without knowing the actual errors, we can't provide a definite solution. This is just one of the most common errors I've seen.

1

XCode can automatically add such subfolders to include search paths. But for android, you should update Android.mk manually (OK, we've done it by automatic parsing *.xcodeproj and generating Android.mk, but it's a bit complicated solution).

 LOCAL_C_INCLUDES :=  \
 $(LOCAL_PATH)/../ \
 $(LOCAL_PATH)/../GameScreen \
 $(LOCAL_PATH)/../HomeScreen
0

Right click the classes folder in x-code and add a new group, then drag the headers/code into it that you want to organize instead of creating subfolders outside of xcode and dragging/dropping them into the classes folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.