Developers Manual > Cocos2d-x > Modules > Debugging > How to debug cocos2d-x games

How to debug cocos2d-x games

Debugging is essential to any project. Cocos2d-x supports many platforms however the tools used on each platform are different and have different capabilities. Because of this some platforms may be easier than others to develop and debug on.

Xcode is very good and provides excellent debugging tools and and excellent simulator.

Win32 is also good with good debugging tools.

Android tends to be difficult for inexperienced Android developers. Users report troubles with Eclipse debugging and issues where simulators wont run or take a very long time to run. This makes it hard to debug.

Porting to Android Platform

Porting a Cocos2d-x game from one platform to another is easy:

The main steps to port from one platform to Android are:

  • Modify Android.mk under proj.android folder.
  • Run cocos run -s path-to-your-project -p android to build the project and install the apk to your phone.

(Note: When you are modifying the Android.mk file, try to include all the compile unit in the LOCAL_SRC_FILES and include the required modules)

Debug Cocos2d-x Lua games

Debugging lua codes requires third-party tools such as Decoda or LuaEdit. Both tools are Windows only.

Decoda

Decoda is a commercial software, which can debug lua without modifying code.

Debugging steps:

  • Use debug mode to build Cocos2d-x lua project in VS2010.

  • Copy all files under projects\testlua\Resources to projects\testlua\proj.win32\Debug.win32

  • Start Decoda.

Select the menu “Debug” -> “Start Debugging[F5]”. In the opening dialog, set the command and working.

  • open Lua source file in Decoda and set a breakpoint.

  • Use keyboard shortcut F5 to restart program to make breakpoint work.

LuaEdit

LuaEdit is a open source software, which can debug lua but you will need to modify code.

Please refer to the official document for more information.

Using the console log to debug.

As a supplement debugging tool, console log is very useful.

C++:

void Log(const char * pszFormat, …)

Lua:

    print

make you own cclog with following code:

    local cclog = function(...)
        print(string.format(...))
    end

JSB:

    cc.log();

or

    log();

01.jpg (184.5 kB) kenan_liu, 2013-10-23 09:40

02.jpg (354.6 kB) kenan_liu, 2013-10-23 09:40

luedit.png (64.8 kB) kenan_liu, 2013-10-29 02:32

Sign up for our newsletter to keep up with the latest developments, releases and updates for Cocos2d-x.