Mac below Xcode+ndk7 Configure COCOS2DX & box2d for game tutorials across iOS and Android platforms

Source: Internet
Author: User

This tutorial shows you how to use Cocos2d-x and box2d to make a demo, and this demo can run both on iOS and Android platforms. Before you continue reading, it is recommended that you read the previous tutorial first.

First, follow the previous tutorial, set up the COCOS2DX and Android development environment under the MAC, and pay attention to the configuration of some environment variables, such as $cocos2dx_root. Then use Xcode to build a cocos2dx_box2d project named Box2dtest, as shown in:

Then, as before, using the COCOS2DX installation directory script to create an Android project, we named the Project Box2dtest.

The next step is to create a makefile:

First, select one of your favorite text editors, then CD to the Box2dtest Android directory just below, then open terminal, enter:

Vim Makefile

A new window will then be created, enter I into edit mode, and then type the following 3 statements
Clean
RM-RF libs/
RM-RF obj/

Please pay special attention to the clean: shelf input, while two RM statements are indented using the TAB key. If you do not indent, you will get an error when you enter make clean.

When you are finished, ESC (back to command mode): Wq Enter, save and exit. OK, fix it, and then enter make clean, if the following output appears, OK:

RM-RF libs/
RM-RF obj/

Next, copy some Android-related files to the previous iOS project. (Note the $ sign + environment variable name, which is the alias of the directory you previously defined, that is, thecocos2dx_root represents your COCOS2DX directory )

The first step is to copy the Android folder from $cocos2dx_root/box2dtest/android/to the iphone's project directory, and the iOS file in the same directory. (The final directory is box2dtest/box2dtest/android/)

The second step is to copy the Android.mk file from $cocos2dx_root/box2dtest/classes/to box2dtest/box2dtest/classes /below

The third step is to copy the android.mk from $cocos2dx_root/cocos2dx/to box2dtest/box2dtest/libs/cocos2dx/

Fourth step, copy the Android folder from $cocos2dx_root/cocosdenshion to box2dtest/box2dtest/libs/cocosdenshion/ Go below.

Fifth step, copy the android.mk from the cocos2dx_root/box2d/to the box2dtest/box2dtest/libs/box2d/.

The final step is to copy the Platform folder from $cocos2dx_root/cocos2dx/platform to box2dtest/box2dtest/libs/cocos2dx/.

Of course, this platform is a bit large, about 114M, which except Android,third_party and iOS three folders can not be deleted, all other folders could be deleted, special attention!!!!

Do not delete those files, a file can not be deleted!!!!

Next, we configure the build_native.sh script to replace it with the following:

# set Params
ndk_root=/volumes/mydata/android-ndk-r7b/
cocos2dx_root=. /libs/cocos2dx
game_root=. /
game_android_root= $GAME _root/android
resource_root= $GAME _root/resources

# Make sure assets is exist
If [-D $GAME _android_root/assets]; Then
RM-RF $GAME _android_root/assets
Fi

mkdir $GAME _android_root/assets

# Copy Resources
For file in $RESOURCE _root/*
Do
If [-D $file]; Then
CP-RF $file $GAME _android_root/assets
Fi

If [-f $file]; Then
CP $file $GAME _android_root/assets
Fi
Done

# Build
$NDK _root/ndk-build-c $GAME _android_root $*

Note that the ndk_root here should be changed to your own path.

Then modify the android/jni/android.mk and modify it to look like this:

Also modify the application.mk to look like this:

App_stl: = gnustl_static
App_cppflags + =-frtti
App_modules: = cocos2dx_static cocosdenshion_shared box2d_shared game_logic_static game_static

Then, change the android/jni/helloworld/android.mk to look like this:

then change the classes/android.mk to look like this: (After the game is bigger, you can add the source files in the Local_src_files . )

Local_path: = $ (call My-dir)

Include $ (clear_vars)

Local_module: = game_logic_static

Local_module_filename: = Libgame_logic

Local_src_files: = AppDelegate.cpp \
HelloWorldScene.cpp

Local_c_includes: = $ (Local_path)/. /LIBS/COCOS2DX \
$ (Local_path)/.. /libs/cocos2dx/platform \
$ (Local_path)/.. /libs/cocos2dx/include \
$ (Local_path)/.. /libs/box2d/\


Local_static_libraries: = png_static_prebuilt
Local_static_libraries + = Xml2_static_prebuilt
Local_static_libraries + = Jpeg_static_prebuilt
Local_whole_static_libraries + = Cocos2dx_static

Local_shared_libraries: = cocosdenshion_shared
Local_shared_libraries + = box2d_shared

Include $ (build_static_library)

$ (call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$ (call IMPORT-MODULE,COCOS2DX/PLATFORM/THIRD_PARTY/ANDROID/MODULES/LIBXML2)
$ (call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)

Then open the terminal and enter:

Make clean
./build_native.sh

If all goes well, you will get the following output:

Gdbserver      : [arm-linux-androideabi-4.4.3] Libs/armeabi/gdbserver
Gdbsetup : Libs/armeabi/gdb.setup
Install : libcocosdenshion.so = libs/armeabi/libcocosdenshion.so
Install : libbox2d.so = libs/armeabi/libbox2d.so
Install : libgame.so = libs/armeabi/libgame.so

Finally, just like in the previous tutorial, open Eclipse, import the project, and then run it OK. The final operation of the v880 is given below:

From the process of configuring box2d, we can see that this is the same as the method configured in the previous tutorial, the only difference is some of the Android Mk file differences. You can refer to the NDK documentation and then combine this example to find out. The next time you configure FFmpeg or other third-party C + + libraries, you can configure them this way.

If someone has successfully configured other third-party libraries, welcome message sharing, learn Lei Feng, good things:)


To exchange the forum, please click the portal.

Reference: http://gameit.ro/2011/08/creating-a-cocos2d-x-box2d-android-project/

Mac below Xcode+ndk7 Configure COCOS2DX & box2d for game tutorials across iOS and Android platforms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.