How To Create Cross Platform Classes

Hi guys! I’m new on Cocos2d-x. How to create a class into the Classes folder and I want the see on Visual Studio, Android Studio etc. but I cant find a resource. How can I do?

Thanks.

1 Like

You need to create your classes in the Classes/ directory.

Then in Android or VS or XCode, you need to add these new source files to your project.

If you are using CMake, then edit your CMakeLists file.

Did you create your project by running cocos new ...?

I tried CMakeLists.txt but not worked for me. I was added CMakeLists.txt and after I tried using #include “example.h”. Is that wrong?

Post your CMakeLists and the name of the source files you want to add, please.

Technically, you just add them, example, if I had a class called SuperMeatBoy.cpp

# add cross-platforms source files and header files 
list(APPEND GAME_SOURCE
     Classes/AppDelegate.cpp
     Classes/HelloWorldScene.cpp
    Classes/SuperMeatBoy.cpp
     )
list(APPEND GAME_HEADER
     Classes/AppDelegate.h
     Classes/HelloWorldScene.h
    Classes/SuperMeatBoy.h
     )

Thanks! @slackmoehrle

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.