1.安装vscode local lua debug插件
2.修改mac/SimulatorApp.mm文件 updateProjectFromCommandLineArgs:(ProjectConfig*)config 函数将
config->setShowConsole(true); 中的true改为false,就是关闭控制台窗口,否则调试插件不生效
3.添加或修改.vscode/launch.json 代码如下,根据实际路径适当修改
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Release",
"type": "lua-local",
"request": "launch",
"program": {
"command": "/Users/ycmac/develope/rok-client/runtime/mac/LOR Mac.app/Contents/MacOS/LOR Mac"
},
"args": [
"-n",
"-a",
"${workspaceFolder}"
]
},
{
"type": "lua-local",
"request": "launch",
"name": "Debug",
"program": {
"command": "/Users/ycmac/develope/rok-client/runtime/mac/LOR Mac.app/Contents/MacOS/LOR Mac"
},
"args": [
"-n",
"-a",
"${workspaceFolder}"
] ,
"scriptRoots": [
"/Users/ycmac/develope/rok-client/src"
]
}
]
}
4.在 src/main.lua中添加如下代码加载调试模块,(被注释的两行)
require("cocos.init")
require("framework.init")
--package.path = '/Users/ycmac/.vscode/extensions/tomblind.local-lua-debugger-vscode-0.2.0/debugger;' .. package.path
--require("lldebugger").start()
-- -- ============= 三消调试 START =============
-- GAME_VERSION = "0.00.001"
-- GAME_MIN_VERSION = "0.00.001"
因为在启动时开启调试影响性能,可在游戏启动后打开调试如下,例如可在view/mainCityView.lua文件中添加
--点击触发监听层
function mainCityView:viewOnClick(ref, event)
if not lldebugger then
lldebugger = {}
package.path = '/Users/ycmac/.vscode/extensions/tomblind.local-lua-debugger-vscode-0.2.0/debugger;' .. package.path
require("lldebugger").start()
end
mainCityHandler.viewOnClick(self, ref, event)
end
--缩放监听
这样在游戏启动后点击一下主界面,就可以调试了。