Version:
Cocos2dx 3.10 Lua
Environment configuration:
Here use VS +BabeLua for editing and debugging
New project:
directly above the picture< span style="font-family:Calibri">(Pay attention to the red frame! )
-workdir D:\310\OneLua -file src\main.lua
< p style="margin-top:0px; margin-bottom:0px; padding-top:0px; padding-bottom:0px; color:rgb(85,85,85); font-family:'microsoft yahei'; font- size:15px; line-height:35px"> Matters needing attention:
1.Add path,The previous version has< /span>,never watched it again.Pay attention to the red frame,You have to join this.
package.path = package.path .. “;src/?.lua”
2. I don’t know which version to start from,Global variables need special instructions
cc.exports.varName = XXX
Be sure to write like this.Otherwise it will report an error
(Update 4.4: I found the problem, just set CC_DISABLE_GLOBAL = true in config.lua to false, don’t disable global variables) p>
3. The print function cannot output
Add engine->executeString(“print=release_print”);
or use release_print directly in the lua code (this is too troublesome, thank you for adding an underscore to a word, I can’t stand it!!!)< /span>
4. Automatic binding events
- local MainScene=class(“MainScene”,cc.load(“mvc”).ViewBase)
- MainScene .RESOURCE_FILENAME=”MainScene.csb”
- local MainSceneEvents={[“Button_1”]={[“varname”]=””,[“events”]={{[“event “]=”touch”,[“method”]=”OnBtnClick”}}}}
- MainScene.RESOURCE_BINDING=MainSceneEvents
- function MainScene:OnBtnClick(event)
- if event. name==”began” then
- print(“event.began”)
- elseif event.name==”ended” then
- print(“event.ended”)
- end
- print(event.name)
- end li>
- function MainScene:onCreate()
- end