Getting started with Cocos2d-x with Visual Studio

Hello,

I am trying to get Cocos2d-x up and running on my PC. I am using Visual Studio 2010 Express on Windows 7 64bit.

So I first tried to follow the instructions on the wiki —> [[http://www.cocos2d-x.org/projects/cocos2d-x/wiki/Cocos2d-x_Application_Wizard_for_Visual_Studio_User_Guide]]
Sure enough the batch file came back with errors. After updating my PATH environment variables for msbuild and xcopy I came up with more errors. Then I found this recent thread —> http://www.cocos2d-x.org/boards/6/topics/30007?r=30265#message-30265
I followed the advice given in the last post and removed the CocosDragonJS and WaterMelonWithMe projects from the solution and tried again. Still doesn’t work. So I thought maybe I needed to remove the CocosDragonJS and WaterMelonWithMe relevant code from the batch file. I did so and still no dice. The attached screenshot shows the output of the batch file.

When I build the solution in visual studio I don’t have any problems. I can run the HelloCpp and HelloLua projects (from VS) but nothing else works all of the other projects complain saying:

Unable to start program: .2d-x-2.1.4\Debug.win32projectname].dll

Not really sure whats up with that either.

Finally, I checked out the comments under the most recent news item: http://www.cocos2d-x.org/news/127#comments and saw that someone had posted a breif description of build issues on VS, and the answer is very cryptic (to me)

VS template has been deprecated. Please use `tools/project-creator` to create multi-platform project instead.

I opened up this folder but all it contains is a python script and a bunch of .json files. I don’t see anything else online referencing this folder or anything in it so I don’t really know if I am supposed to be doing anything there.

As you can probably tell I am new to cocos2d-x and I am not really getting what the end result of this is supposed to be. The wiki guide is talking about VS project templates. That does not really sound appealing to me. I would rather just use the libraries like any other api (e.g. BOOST, Allegro, box2d). I had no real trouble setting any of those up but I have found the setup of cocos2dx to be quite mystical. However I understand that 2.1.4 was just released this week so I understand there may still be issues.

I would appreciate any advice that anyone has to offer.

Thanks,
Nolan


build errors.png (90.2 KB)

1 Like

First of all, here’s the wiki page on the python script for creating new multi-platform projects: http://www.cocos2d-x.org/projects/cocos2d-x/wiki/How_to_create_a_multi-platform_project_in_one_command_line
It’s a little hidden away in the wiki, but afaik it’s THE way to create new projects.

As I switched over to using 2.1.4, I didn’t even try to run the build-win32.bat, as I didn’t have much luck with that even in the past. I just used the python script to create a new multi-platform project, and the Visual Studio project created there worked well. I seem to recall that the only hiccup I had was having to add COCOS_DEBUG=1 to liblua to make lua’s print() to work.

Well, there is another hiccup. You need to have all your project’s resources in the executable path. To combat this you could add the line “xcopy /Y /E …* $(OutDir)” to your project’s Post Build Events commandline.

Now that I tried to just go ahead and open TestCpp project from Samples/Cpp, it didn’t work out of the box either. It’s references were all messed up. I went to the Project’s properties > Common Properties> Framework and References (I’m using Visual Studio Express 2012 btw) to see which projects I needed, manually went and found them all, added them to the solution, then removed all the existing references and added them again. After that I could build it. After copying the Resources to Samples/Cpp/TestCPP/proj.win32/Debug.win32/ I was able to run the executable in that folder also.

I hope this helps you some. I had a devil of a time trying to get anything to work the first time. I’m not at all experiences with VS so I’m probably still doing many things the way I shouldn’t :stuck_out_tongue:

Sami,

Thanks for your help.

First I will talk about my success. I followed the link you attached (which, with your instructions was very helpful). I downloaded and installed the most recent version of python with relative ease (took about 5-7 mins). Then I tried to run the create_project.py script. It complained about a myriad of errors. I quickly realized that these errors were because the script was not Python 3 friendly. So instead of getting an older version of python I updated the script (see attached) and it works like a charm. :slight_smile: I created a test solution in VS Express 2010 and built all the projects in it with no issues (HelloCpp,libBox2D,libChipmunk,libcocos2d,libCocosDenshion, and libExtensions). The only one that runs is HelloCpp. I’m pretty sure that is by design. The rest of them are just for building libraries, correct?

I’m not really dying to build the examples in all their glory. I just want to know that I can get access to all of the cocos2d-x core features. So thanks for the tip about Samples/Cpp but I didn’t try too hard to get that to work.

This is where I get confused: you said

[The create_project.py script is] THE way to create new projects.

Why is that? Why shouldn’t I just take the relevant .lib and .dll files from this create_project test build, put them in a known location and include that location in all of my cocos2d-x projects? Or would that not allow projects stored elsewhere on my computer to be cross-platform? I noticed that all of the .lib and .dll files are under C:2d-x\cocos2d-x-2.1.4\projects\TestProject\proj.win32\Debug.win32 Does this mean that those .lib and .dll files are created new for every project I create?

Also the proj.[platform] folders are a little confusing. Do the computer platform folders (i.e. Linux,Mac,win32) contain files for developing on those platforms (as I have been assuming), or developing for those platforms, or both? I understand that cocos2d-x primarily targets mobile platforms, but it’s kind of unclear if it can be used for developing for computer platforms as well. Your input here would help clear things up.

Thanks!

Okay I’m beginning to feel I’m a bit out of my depth (Did I mention I’m new and not really sure I’m doing things properly in the first place :slight_smile: ) but let’s see…

You’re right about the thing. Just the HelloCpp will produce an executable and the rest are libraries.

I guess I never thought much about why all of the libraries get created (it might be copied, I’m on a laptop right now and can’t check) to your project’s directory, I just assumed it’s something to do with also having to copy all your resources to the same directory. Like it’s the only way the executable will find them, unless you add the libraries to your PATH or something. I don’t know why you wouldn’t do that. I have just been happily coding away at my single project so it didn’t bother me much, yet. I would be happy if you find a nicer way of sorting things, and share it here ^^

The contents of your new project folder should pretty much tell you which platforms (desktop platforms included) you could potentially unleash your game for. In the Mac folder you’ve got an xcode project that you can use to build your multi-platform project for desktop Macs. You could also do your developing there if you wished, but the point is that to publish your game for mac. The iOS folder is separate, and is used to create the same game for iOS devices. Haven’t tried Linux but I assume it works the same way.

There is some variation to what platforms are currently supported by your choise of language (cpp/lua/javascript), and with desktops you could run into other caveats such as having to hack the engine to enable keyboard input. I believe they’re going to have keyboard support in the next version of cocos2dx, though.

Sami,

Thanks for your ideas. Eventually, I will look for a better solution to the .lib/.dll problem (and if I have any epiphanies I will post them here), but for now I am ready to just dive in and start coding.

Thanks for the tip about keyboard input, I would otherwise have assumed it was supported.

Happy Coding,
Nolan