Windows workflows

I am new to working with cocos2d-x and was wondering what workflows tools other devs use to build on windows for mobile devices. Im also searching for info like: when adding a source file what are all the places you need to update? for example I noticed you need to update the cMakeLists file. I didn’t see anything about this going through the programmers guide, unless I missed it. Are there other things like this I should be aware of?

Hello and welcome to cocos2dx.

In Android studio just create a Class then as you said update the CMakeLists.txt add the ClassName.cpp and the ClassName.h you will see the format in there. have you got a project compiling on android studio yet? id be very happy to do a quick video to get you up and running.
Tools I use are , Android studio, Texture Packer, GIMP & Audacity for sound.
Let me know what stage your at. I don’t use any Gits as I have WD 4100ex on network for backups.

Hey thanks for the response, I had gotten the cpp-tests folder working. But when doing new code on a blank project I have not gotten it to work. I am using visual studio to test as I develop, made the files by hand and imported them because when adding new in Visual Studio it was placing them outside of Classes/ . I currently have the test project code done and working in debug, but cannot get it working in android studio. Yes any help would be amazing, especially since I have never gotten the hang of android studio.

Everything must go into a “CMakeLists.txt”, whether you add the .cpp/.h to the root CMakeLists file, or you break it up and add CMakeLists.txt to sub-directories, and reference them from the root one, it’s entirely up to you.

Once you make any changes to CMakeLists.txt, you must do one of two things, either re-run the cmake command in a console window to re-create the Visual Studio solution and project files, or right click the “ZERO_CHECK” project and build that (which should do the same thing as running the cmake command via the CLI). If for any reason you get errors, then chances are you’ve updated something that requires you to delete the [build_folder]/CMakeCache.txt file, and then re-do one of the above steps.

Android Studio doesn’t require you to manually run cmake, since it handles that task automatically within the IDE when you do a gradle sync.

For Xcode, it’s the same process as Windows, where you manually need to run the cmake command to recreate the project files on any changes to “CMakeLists.txt”.

To save myself time, I just created a batch file and put it in the root directory of my project, and when I need to, I simply run it to re-run cmake and refresh the build folder.

For example, to create a Visual studio 2019 (x86/Win32) solution in a directory named “build-win32”:

IF EXIST .\build-win32\ GOTO RUNCMAKE
mkdir build-win32
:RUNCMAKE
cmake -S . -B build-win32 -G "Visual Studio 16 2019" -Tv142 -A Win32

For Visual Studio 2022, you can do this:

IF EXIST .\build-win32\ GOTO RUNCMAKE
mkdir build-win32
:RUNCMAKE
cmake -S . -B build-win32 -G "Visual Studio 17 2022" -A Win32

If you put the above code in something like “vs-run-cmake.bat” or similar, drop that file in your project folder. Just run this file any time you make changes to “CMakeLists.txt” to refresh the VS solution files.

So if I have the visual studio build working and can run my game, but then I try to run in android studio and get problems. What should I be looking for? Besides updating cMakeLists.txt should it be automatic otherwise? If it’s automatic I may have some wrong settings or missing skd/ndk? I ran cpp-test and hello world(new project) both were compiling properly in VS and Android Studio, then after making more files(1 cpp and 2 h files and added to cmakelists), trying to mimic helloworldscene (.cpp+.h files) it not longer builds in Android Studio, only works in VS.

Well, that depends. Does a new clean project work before you add new source files?

Just do a quick test. Create a new project, then in Android Studio, open the “proj.android” folder. It should do a gradle sync automatically, or you can force the sync at any time by selecting “File”-> “Sync Project with Gradle Files”, as you see in this screenshot:
image

If that project doesn’t work, then check the errors to figure out why. If it’s an SDK/NDK issue, then it should be trivial to fix.

Once you have the Android build working, then that would be the right time to add new source files. Create new files, and add them to your “CMakeLists.txt” (in the same section you see HelloWorld.cpp/.h etc). You then need to re-sync the build files, so use the menu item in the above image to do that. When the sync completes, you should now be able to build the project again. If it doesn’t work, it won’t have anything to do with the SDK/NDK, but rather something in your source files or “CMakeLists.txt”.

Ya so those are the steps I tried to do at first. I am starting a new project just to make sure. It is indeed working,

.

So now how should I go about adding files now, and where? I would think they go in the …/Classes/ folder, but you can’t see that from inside the android studio project correct?

You should see the “HelloWorld” source files in there, but from your screenshot it looks like the same old problem with Android Studio and cocos2d-x. The project still works, but the “cpp” folder in the Project view on the left doesn’t show the files.

The source code can go into the “Classes” folder, and then you add a reference to the source in your CMakeLists.txt and re-sync. Even though they aren’t displayed in Android Studio, the project will build correctly.

Now, the actual cause of the files not showing up in Android Studio is a mystery. It did happen in my setup too, but I never did figured out what was causing it. It did eventually work (I think), perhaps because of updating to the latest gradle version, or some other change I had made, but I can’t quite recall. This issue is not present in this fork of Cocos2d-x that is actively being maintained, so maybe something was fixed in there to solve that IDE issue.

Thanks a lot for the help, got it working now. Is it best to develop inside of android studio the whole time? How do most devs get an android+ios game working? Gotta run it through multiple IDEs?

I don’t know how most devs do their development, but for me personally, the majority of the work is done on Windows using Visual Studio. Once the Windows build of the app is working, then I switch over to Android Studio to do any Android specific development, and likewise for Apple platforms, where I switch to using Xcode for anything specific for that platform.

I use android studio android, I just plug in my android device by usb that’s in debug mode, Android automatic pick it up in the IDE and and i just hit Compile or the Play button Android studio will deploy the app striate to the device it and run automatically + I have debug console.

IOS you have to use Xcode and join there Apple development program and that’s not free. its a real pain in the neck getting the project synk with the apple account also you have to register an apple device on the account in order to test on a device.

I would say develop the game in android then when wanting to deploy to apple then open your proj.ios_mac in xcode and add all the files and bit’s you need. You have to convert sound files .caf but its should be all the same you will have to edit some compiler settings as well I think you have to add ccp and .h file somewhere in the build setting . Setting up with mac is pain as they update there os all the time and it sometimes break the build i’m seeing a lot on the forum that it won’t build on the new M1 chips, and of coerce your being forced to upgrade all the time by apple I just stopped using them as I was spending more time fixing apple problems then writing code.
I hope this helps you.

Thank you guys for the answers, looking for a simple .gitignore so that I can share and other user can compile it themselves. Using the one from the cocos2d-x 4.0 github page at the moment.

Why would you want to do that? I’ve never had to convert any audio file to CAF format (MP3 and OGG formats work fine), so I’m curious to know why you stated that you need to convert them.

Because .caf is the mossed optimised for IOS. I don’t know if iOS can do ogg. it will probably do wav format. But you know what apple is like do it there way or the highway.

Hay M8 done a quick Video on using android for you it’s really not that hard. its my fist vid on cocos2dx.
hope this help you out.

I didn’t know that about the CAF format. As for OGG, I just quickly checked the resources on the iOS build of the app I’m working on, and all file seem to be MP3 format, so now I’m not certain if OGG does work or not on iOS.

Very nice of you, I will check it out.

Let me know if you need more video’s id be happy do a tut on cocos2dx ill get the admins to do a sticky the admins on here are fantastic and very very helpful.

Hey man thanks for the video. Perfect for getting started with windows/android studio.

Couple ?'s:

  1. Where did you find which gradle versions to use? I had problems there until I randomly found those version numbers.
  2. Since you used it, will Update() not run until scheduleUpdate() is called?
  3. What are the best resources you found to learn Cocos, am I missing any? Right know I know about:
    -Programmers guide
    -The API docs
    -Looking through the tests that come with engine

Thanks again for taking the time to make that video.

Yes you need to call scheduleUpdate(); that will start the loop of update(float dt);
you can make your own timers too.
this->schedule( SEL_SCHEDULE( &MyClass::TimerCallback ), 0.18f , 6 , 1 );

if your looking for book look for “cocos2d-x Cookbook”, Akihiro Matsuura, PACKT publishing
its in a pdf format so you can just cut copy and past it will help you setup and handle touch inputs animation,
but also checkout, https://docs.cocos.com/cocos2d-x/manual/en/

if its getting too technical you can ask here the people on this forum are really great and quick to help out and answer.