原文地址:https://www.namidame.tech/Cocos2d-x-3.10-Lua-demo.html
本文介绍Cocos2dx-3.10环境下运行官方Lua示例Demo的方法
官方Demo直接运行貌似会报错,有一些lib找不到,所以推荐新建一个工程来运行
新建工程
- 执行命令
cocos new lua-tests -l lua -t binary
-t binary参数生成引用预编译库的工程,这样就不用花时间去编译,因为这里不需要改cocos框架的源代码,所以选择生成预编译工程
复制资源
- 进入cocos所在目录C:\Cocos\Cocos2d-x\cocos2d-x-3.10\tests\lua-tests,复制src,res文件夹到工程根目录下,覆盖原文件
- 进入目录C:\Cocos\Cocos2d-x\cocos2d-x-3.10\tests\cpp-tests\Resources,将所有资源复制到lua-tests\res目录下
- 进入目录C:\Cocos\Cocos2d-x\cocos2d-x-3.10\external\lua\luasocket\script,将所有文件复制到lua-tests\src目录下
复制工程文件
-
进入C:\Cocos\Cocos2d-x\cocos2d-x-3.10\tests\lua-tests\project\Classes目录,将下面5个文件复制到lua-tests\frameworks\runtime-src\Classes目录,覆盖原文件
编辑AppDelegate.cpp,将入口函数改为src/controller.lua
bool AppDelegate::applicationDidFinishLaunching()
{
//...其他代码
#if (COCOS2D_DEBUG > 0) && (CC_CODE_IDE_DEBUG_SUPPORT > 0)
//...其他代码
#else
if (engine->executeScriptFile("src/controller.lua")) -- 更改入口函数
{
return false;
}
#endif
return true;
}
用VS运行win32工程即可
查看src/mainMenu.lua,可知Lua示例并未支持所有功能
local _allTests = {
{ isSupported = true, name = "Accelerometer" , create_func= AccelerometerMain },
{ isSupported = true, name = "ActionManagerTest" , create_func = ActionManagerTestMain },
{ isSupported = true, name = "ActionsEaseTest" , create_func = EaseActionsTest },
{ isSupported = true, name = "ActionsProgressTest" , create_func = ProgressActionsTest },
{ isSupported = true, name = "ActionsTest" , create_func = ActionsTest },
{ isSupported = true, name = "AssetsManagerTest" , create_func = AssetsManagerTestMain },
{ isSupported = true, name = "AssetsManagerExTest" , create_func = AssetsManagerExTestMain },
{ isSupported = audioEndineSupported, name = "AudioEngineTest", create_func = AudioEngineTest},
{ isSupported = false, name = "Box2dTest" , create_func= Box2dTestMain },
{ isSupported = false, name = "Box2dTestBed" , create_func= Box2dTestBedMain },
{ isSupported = true, name = "BillBoardTest" , create_func= BillBoardTestMain},
{ isSupported = true, name = "BugsTest" , create_func= BugsTestMain },
{ isSupported = true, name = "ByteCodeEncryptTest" , create_func= ByteCodeEncryptTestMain },
{ isSupported = true, name = "Camera3DTest" , create_func= Camera3DTestMain }
}
著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者: 你很德布罗意
邮箱: namidame@sina.cn
博客地址: https://www.namidame.tech/
原文地址: http://www.namidame.tech/Cocos2d-x-3.10-Lua-demo.html