Developers Manual > Cocos Code IDE > Debug With Code IDE > How to Debug Cocos2d-x Lua Game Using Code IDE

How to Debug Cocos2d-x Lua Game Using Code IDE


Supportive Debugging Environment

On Windows you can debug Windows and Android games, and on Mac you can debug Mac, iOS and Android games.

This manual makes use of Mac as development environment, and here we will show you how to use Code IDE. The process on Windows is essentially the same.

Prerequisite


Please refer to Cocos Code IDE if you have not completed the installation of Cocos Code IDE.

IDE Configuration


Basic Settings

Open Preferences/Cocos/Lua page, select the directory of cocos2d-x 3.x you just downloaded to be Lua Framework.

Since v1.2.0 In Preferences/Cocos/Frameworks page, select Enging Mode and set the directory of cocos2d-x 3.x you just downloaded to be Lua Framework.

Additional Settings

You should provide compiling tools in Android if you need to replace the Android runtime we provided. Open Preferences / Cocos page.

Debug the Game


  1. Create a new Cocos Lua project and name it CocosLuaGame.
  2. Click Debug button on toolbar
  3. The script will be running on Runtime of Mac version we provided by default. If you want to debug program on other target platforms we provided, please refer to How To Debug on Other Target Platforms.

How to Debug


Breakpoints Supporting

  • You are able to create breakpoints in Lua script files.
  • When the breakpoint is triggered, select "Yes" to open Debug Perspective, and you will find many useful debug views, Call stacks, Variables, Breakpoints, etc.
  • Step over, Step into, Step out are also supported

Code Hot Updating

Do you want to change the moving path of SpriteDog?

The "tick()" function controls the SpriteDog's position.

1
2
3
4
5
6
7
8
9
10
11
12
-- moving dog at every frame
local function tick()
    if spriteDog.isPaused then return end
    local x, y = spriteDog:getPosition()
    if x > origin.x + visibleSize.width then
        x = origin.x
    else
        x = x + 1
    end

    spriteDog:setPositionX(x)
end    

Modify the implementation of function, for example, change the value 1 to 10 and save your change.
Then you will find that you have improved the speed of SpriteDog without restarting the app!

How to Debug on Other Target Platforms


  • Open “Debug Configurations”page by clicking Debug Configurations button on toolbars
  • On the left side of the page, select the configuration named CocosLuagame we created just now.

Debug on iOS Simulator

  • Check iOS Simulator radio button
  • Choose a runtime app
  • Then click the Debug button
  • IDE will auto-install chosen runtime app and start runtime to debug

Debug on iOS Device

  • Firstly, you need a runtime IPA, you can build a custom runtime IPA by Code IDE from version 1.0.0-rc1, then Install runtime IPA to iOS device.
  • On "Debug Configuration" page, Check Remote Debug radio button
  • Select "iOS" platform
  • Enter IP address of your device into the Target IP and select the IP address that your PC used on the Host IP(Make sure that the Target IP and Host IP can access each other)
  • Then click the Debug button

Debug on Android Device by ADB Mode

  • Check Android ADB Mode radio button
  • Choose a runtime apk
  • Click the Debug button
  • IDE will auto-install chosen runtime apk and start runtime to debug

Debug on Android Device by WLAN

  • Manually install runtime apk to your device. It is placed in CocosLuaGame/runtime/android.
  • Start the runtime on device manually
  • On "Debug Configuration" page, Check Remote Debug radio button
  • Select "Android" platform
  • Enter IP address of your device into the Target IP and select the IP address that your PC used on the Host IP(Make sure that the Target IP and Host IP can access each other)
  • Then click the Debug button

Enjoy!

lua_breakpoint.png (167.1 kB) honghui.zhang@chukong-inc.com, 2014-07-18 10:42

lua_config_button.png (18.8 kB) honghui.zhang@chukong-inc.com, 2014-07-18 10:43

lua_debug_button.png (17.6 kB) honghui.zhang@chukong-inc.com, 2014-07-18 10:43

cocos_preferences.png (87.4 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:21

lua_remote_mac_debug.png (26.9 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

lua_android_debug_config_adb.png (34.9 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

lua_cocos_preferences.png (47.2 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

lua_ios_sim_debug_config.png (22.6 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

lua_remote_android_debug.png (29.5 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

lua_remote_ios_debug.png (28.4 kB) honghui.zhang@chukong-inc.com, 2014-08-12 10:22

en.md (4.5 kB) yuxinwork@163.com, 2015-02-28 08:38

lua_cocos_preferences_above_1.2.0.jpg (148.1 kB) yuxinwork@163.com, 2015-02-28 08:38

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