-
Book Overview & Buying
-
Table Of Contents
Cocos2d-x cookbook
By :
You must finish the first recipe before you begin this step. If you have not finished it yet, you will need to install Eclipse.
NDK_ROOT:
NDK_ROOT, and the value is NDK_ROOT path:

~/Documents/MyGame/proj.android:
cocos2d lib at ~/Documents/MyGame/cocos2d/cocos/platform/android/java, using the following command:importing cocos2d lib

Run icon

cpp files into your project, you have to modify the Android.mk file at ~/Documents/MyGame/proj.android/jni/Android.mk. This file is needed to build the NDK. This fix is required to add files.Android.mk would look as follows:LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cppTitleScene.cpp file, you have to modify it as shown in the following code:LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp \
../../Classes/TitleScene.cpp The preceding example shows an instance of when you add the TitleScene.cpp file. However, if you are also adding other files, you need to add all the added files.
You get lots of errors when importing your project into Eclipse, but don't panic. After importing the Cocos2d-x library, errors soon disappear. This allows us to set the path of the NDK, Eclipse could compile C++. After you have modified the C++ codes, run your project in Eclipse. Eclipse automatically compiles C++ codes, Java codes, and then runs.
It is a tedious task to fix Android.mk again to add the C++ files. The following code is the original Android.mk:
LOCAL_SRC_FILES := hellocpp/main.cpp \
../../Classes/AppDelegate.cpp \
../../Classes/HelloWorldScene.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesThe following code is the customized Android.mk that adds C++ files automatically:
CPP_FILES := $(shell find $(LOCAL_PATH)/../../Classes -name *.cpp) LOCAL_SRC_FILES := hellocpp/main.cpp LOCAL_SRC_FILES += $(CPP_FILES:$(LOCAL_PATH)/%=%) LOCAL_C_INCLUDES := $(shell find $(LOCAL_PATH)/../../Classes -type d)
The first line of the code gets C++ files to the Classes directory into the CPP_FILES variable. The second and third lines add C++ files into the LOCAL_C_INCLUDES variable. By doing so, C++ files will be automatically compiled in the NDK. If you need to compile a file other than the extension .cpp file, you will need to add it manually.
If you want to manually build C++ in NDK, you can use the following command:
$ ./build_native.py
This script is located in ~/Documents/MyGame/proj.android . It uses ANDROID_SDK_ROOT and NDK_ROOT in it. If you want to see its options, run ./build_native.py –help.
Change the font size
Change margin width
Change background colour