How to Debug Cocos Lua Game Using Cocos Code IDE
Supported Debugging Environment:
| Platform |
Mac App |
Android Apk |
iOS App |
Win32 Exe |
| Mac OS X |
Yes |
Yes |
Yes |
No |
| Win32 |
No |
Yes |
No |
Yes |
Let's take Mac OS X as an example, the processe are almost the same.
Prerequisite
If you haven't installed Cocos Code IDE, please read Getting Started first.
Run and Test Game
- Create a new Cocos Lua Project
- Right click the project in the Cocos Explorer
- In the pop-up menu, select "Debug As->Cocos Luabinding", this will create a debug configuration with your project name
- as default, it will run the project's lua script on the Mac prebuilt app .
How to Debug
Breakpoints
- Add breakpoints to lua source files, for examples, line 69 in main.lua
- When the spriteDog arrive at the right edge of the screen, the breakpoint will be triggered
- Select "Yes" button to open Debug Perspective, and you will find many useful debug views, Callstack view, Variables view, Breakpoints view, etc.
- Step over, Step into, Step out are also supported
Live coding
Do you want to change the moving path on the fly?
The "tick()" function in main.lua controls the spriteDog's position.
-- 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
play around with the values, such as changing the value 1 to 10 and save your change.
Wow, the spriteDog changed its moving path without restarting the app!
How to debug on other target platforms
- Open Debug Configurations via Menu Run->Debug Configurations
- On the left side, select the configuration under Cocos Lua Application that you have created earlier
iOS simulator
- Check iOS radio button
- Check Use iOS Simulator
- Then click the Debug button
iOS devices
- Install the runtime app to your device via Xcode
- Start the runtime on your device
- In "Debug Configuration" window on your computer, Check iOS radio button
- Uncheck Use iOS Simulator
- Fill your device local ip address to the Host field
- Then click the Debug button
android devices
- Install runtime apk to your device
- In "Debug Configuration" window on your computer
- Fill device local ip address to Host
- Select your mac ip address in Connection Properties
- Optionally: Check Use Adb Mode if you have installed adb
- Then click the Debug button
Enjoy!