cocos new -p com.honesitconsultancy.indiegame -d "D:\Cocos\Projects" -l cpp
Fig - 1: An empty Cocos2d-x Project |
A new Cocos 2DX C++ project is created through a Python programming language script, remember Python was listed in the list of software we need to install beforehand. To read about list of prerequisites needed to create cross platform games with Cocos2d-x is visit following link:
Fig - 1 shows a new empty Cocos2d-x project. You can see it already contains projects for iOS, Android, and Windows(win32).
How to create new project using Cocos2d-console
Well that's just a fancy name for a Python script. Even the file name is different, "cocos.py".When you install Cocos framework, the path is automatically configured and you can type "cocos" anywhere on command prompt.
This script file is present in Cocos framework installation folder(FYI). In my case I installed it on path "C:\Cocos". Full path of Cocos2d-x is given below:
C:\Cocos\tools\Python27\Tools\Scripts
The how-to guide present on Cocos website tells a different path, I couldn't find it on my PC and discovered this by just searching for .py files in the installation folders.
Launch command prompt, and type the command given below
cocos new -p com.honesitconsultancy.indiegame -d "D:\Cocos\Projects" -l cpp
Important: Please create the project path folders before running the command, i.e. the path specified through -d switch.
Fig-2: cocos2d-x console screenshot |
To learn more about the Cocos2d-X console, type following command to get the list of Cocos2d-x console options
cocos new --help
A screenshot of the help description is shown below
Fig-3: Cocos console help |
How to write Cocos2d-x code using Visual Studio 2012
Go to the path which you specified in command line for creating a new project. Please refer back to Fig-1.Open the folder "proj.win32", this folder will contain a solution file which will be named "indiegame.sln" or "MyCppGame.sln" in my case.
Fig-4: Cocos2d-x new Windows(win32) Project contents |
Fig-5: Inside Visual Studio 2012 Cocos2d-x C++ Project |
Where will you write the code?
To start with we will put the code inside HelloWorldScene.cpp file. If you're going through the programmer guide doc, try your practice code in the C++ function mentioned belowbool HelloWorld::init()
Here's a short video demo to show off and make you jealous :D
For places with Youtube blocked, Vimeo video
Cocos2dx Visual Studio Helloworld Demo from Naeem Akram on Vimeo.
What about Android, iOS and other platforms?
First of all, refer to Fig-1 you will see there's a folder "Classes". This folder is utilized by Cocos2d-x framework to generate object files/dlls which are then used by all projects. Any change you make in Classes folder will be systematically used in Android, iOS,Windows, and Windows Phone Project(what?).Just yesterday I figured how to build and run a Cocos2d-x game project on my Android phone. In a few days I will write another blog post about how to run your Cocos2d-x indie game project on Android using NDK(Native Development Kit) and Eclipse IDE.
Stay with me on this journey to learn game programming, and feel free to communicate/ask questions. You may post a comment or send me an e-mail through the form on right side of page.
Stay tuned for more!
เว็บตรงสล็อต Your lucky stars are shining tonight.
ReplyDelete