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.
cocos run -s path-to-your-project -p androidto 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 is a commercial software, which can debug lua without modifying code.
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
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 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.
void Log(const char * pszFormat, …)
make you own cclog with following code:
local cclog = function(...) print(string.format(...)) end