About 'cocos new' and generating new projects

About 'cocos new' and generating new projects

I have some questions/concerns:

  1. When I create a new cocos2dx project with the cocos new command there’s a flag named -e or `–engine-path, which sounds like it would allow me to specify a folder where the engine is located if I didn’t want the engine to be copied to the new project folder. However, using this flag doesn’t seem to do anything… or does it? Can someone please explain it for me? :slight_smile:

  2. Related to the above, I definitely don’t need a new copy of the engine everytime I create a new project, how can I tell Visual Studio (or, if there’s some file with configurable build paths) where the engine is located? I wish there was a way to put the engine in one place and use that all the time for every new project.

  3. There’s stuff in the engine that you don’t always use when making a simple 2D game, like physics (box2d/chipmunk), 3D physics, etc. is there a simple way to create a new project that’s a little more lightweight and more focused on 2D graphics (with or without 2D physics)?

One way could be to use json-files with all the options and flags you want, and then give that as input to the cocos new command, like:

// proj_config.json
    engine-path: <path>,
    language: <cpp|lua|js>,
    physics: <box2d|chipmunk|bullet|all|none>
    gamepad-support: <y/n>,
    etc. etc....

and then you could just:
cocos new NewGame -settings proj_cpp_nophysics.json

Well, it’s an idea. I mostly want to be able to easily specify the engine path… And the ability to easily use prebuilt libraries would also be nice.


For point 2, you can always use symbolic links.

If you’re using Windows or Linux, refer to this guide.

Create your project as you normally would. Delete the cocos2d folder from your project, and then create a link named cocos2d in it’s place that points to where the cocos2d installation is. The specific type of link you want to use would be a symbolic link or junction link.

1 Like

#1 I don’t know if this actually works. I’ve never tried it, not do I know anyone using it.

#2 @R101 has the idea of symlinks, this is what I do.

#3 you can turn off some in ccConfig.h but also I hope the linker would remove unused classes too.


Thanks for the replies.

Do you know if it’s necessary to compile the cocos2d project I’m linking to first?


Sorry I don’t follow that…can you explain a bit more?


I mean, after unzipping cocos2dx3.xx, do I need to go into that folder and compile it before I can use it for other projects? I created a link as you advised (from a fresh project, after deleting the generated cocos2d folder), but got some kind of error (don’t remember what it was). After that, I unzipped cocos into a new folder, compiled it and pointed my link to the new folder, and then it worked. However, I can’t remember if I did something else besides that…


Sorry, what did you compile? Into pre-builds? Can you show me that step?


First I unzipped cocos2d-x-3.17 - enter that folder when it’s done.
In folder named build open cocos2d-win32.sln and compile it. That’s all.


Ah windows. I see. Yes you need to do that at least once or when updating. I script it. They your symlinks to the libraries will all point to what you compiled. It works a bit different for each platform but I general the same concept applies.


I looked into that ccConfig.h file (didn’t know where it was located first) and it had some interesting settings in it, like CC_NODE_RENDER_SUBPIXEL and CC_USE_PHYSICS etc. but my concern with this file is its location. Its location is under cocos2d/cocos/base/ and if you want to create symlinks from multiple projects to this single cocos2d folder, the settings you want to make for one project might not be suitable for another project. This makes me wish I could use specialized ccConfig.h files when I needed to (per project). Is there a way to accomplish this?
Also, it’s safe to modify this file whenever you want during development, right?


I copy versions of files in a script per project. Then replace with a default version from an original source.


You mean you have a script that copies files (like ccConfig) to the cocos2d folder from your project folder and then compiles the project for you?


Yes I do have scripts.