Whats cocos2dx? Cocos2dx is a game engine branched from Cocos2diPhone, which consists of expanding supported platforms, with multiple choice of programming languages thats shares the same API structure.
Trang 1Install Cocos2d in window
Writer: Team V
Trang 3● What's cocos2dx?
Cocos2d-x is a game engine
branched from Cocos2d-iPhone, which consists of expanding
supported platforms, with multiple choice of programming languages thats shares the same API
structure.
Trang 4http://dl.google.com/android/ndk/android-ndk-r8e-Cygwin: http://cygwin.com/setup.exe
Trang 5Setup tools.
Cocos2dx package: unzip package that we have just download
Build package:
2 option: (only use one of them)
1 Build by build-win.bat: Go to root folder of
cocos2d and run build-win32.bat
2 Use Visual Studio 2010: Open
cocos2d-win32.vc2010.sln in root folder of cocos2d and
build all project in this solution
Trang 6Setup tools.
Android NDK package: unzip this package
Install Cygwin: open setup.exe, when we meet
“select package” screen, we choose the same at below image
Trang 8Ex: InstallWizardForVC2010Express for Visual
Studio Express 2010
Trang 11Build native code for project: Run build_native.sh in prject, in cygwin terminal you must go to current path of project and run “build_native.sh”
Ex: sh build_native.sh
Trang 12Import project to eclipse and run on emulator
Enjoy!
Trang 13Errors that we can meet.
Config wrong paths for android sdk, android ndk, cygwin, etc
Cannot run on emulator: open virtual device in device manager and check “USE HOST GPU”
Trang 14Tip: setup crossplaform project
In tutorial above we can create android project
So we need create win32 project that use source code the same at android native source code
Step1: create android project
Trang 15Step 2.1: in VS create win32 project that have the same name android project
Complete
Trang 16Step 2.2: If you choose ‘Create new solution’, go to step 3
Trang 17Result of step 2.2:
Trang 18Step 3: delete *.opensdf, *.sdf, *.sln, *.suo
– Result:
Trang 19Step 4: move “proj.win32” to the same struct folder
as proj.android
Trang 20Step 5: open proj.win32 by VS and save solution file
in coco2sx root path
Trang 21Tip: Config “include” path for VS
open <project name>.win32.vcxproj by notepad++
Find <AdditionalIncludeDirectories> tag, and add
folder path that VS need search it to find “include” file
Trang 22Tip:How to setup in Eclipse to work with C++
Trang 23First, we need install C++ to Eclipse:
Go to Help/Install New Software
In “Work with” dropdown, select your eclipse version.
Finding “Programing Languages” and select
“C/C++ Development Tools” and “C/C++
Development Tools SDK”
Click Next and install them.
Trang 25We have the android project after create by “create-android-
project.bat” and build by Cygwin throught “build_native.sh”.
Now, we’ll import that android
project to Eclipse.
Trang 26Then, select the project.
File->New-> Other
Select “Convert to a C/C++
Project (Adds C/C++ Nature” And Click Next
Trang 27Select “Make file project” and select
“Other toolchain”
Click “Finish”
Trang 28Right click in your project->
Properties
In “C/C++ Build” , modify like the
image below with “HelloCaiTo” be replace by you project name
Trang 29Next, in “C/C++ General” ,select
“Paths and sysbols”
In “Includes” tab , select “GNU C+ +”
Click “Add ”
Trang 30-After click “Add ” ,choose “File system” and select to your android
NDK->platforms->{Select your android version} ->arch-arm->usr->include
Click OK
-And add the same with {Location of cocos2d-x}/cocos2dx/include (see image) -Click “Apply” and rebuild project
Trang 31Then, go to “Source Location” tab
First it do not contain the “Classes” and the “cocos2dx” like the image.
Trang 32We need to add to your project.
Select “Link Folder ”
Check “Link to folder file system ” and
“Browse ” to your “Classes” folder in your
project-> “OK”
Do the same with your “cocos2dx” folder in the location which you save your cocos2d-x
- Click “Apply”
Trang 33Modify NDK root/build/core/build-binary.mk
Go to line: 49
Change: $(cleantarget):
PRIVATE_CLEAN_FILES := ($(my)OBJS) To: $(cleantarget):
PRIVATE_CLEAN_FILES := $($
(my)OBJS)
Trang 34There is a second issue that only affects Max OS X
developers using the 64-bit NDK (i.e the download
with the file name
android-ndk-r8e-darwin-x86_64.tar.bz2) The fix is trivial and requires you to make the following one-line changes to these two files:
Trang 35{ANDROID_NDK_root}/build/core/init.mk: Re place line 229:
ifneq (,$(shell file -L $(SHELL) | grep
‘x86[_-]64′))
with this:
ifneq (,$(shell file -L $(SHELL) | grep
‘[xX]86[_-]64′))
Trang 36Now, clean your project and run