Use of Cocos2d-x scripting language Lua
The previous blog has introduced the basic knowledge of Lua, this blog will introduce how to use the Lua script language in the Cocos2d-x project for development. Since I use the Mac system, so the demo for everyone to run our Cocos2d-x project in XCode.
Introduce the development environment of the author:
- Cocos2d-x 3.1.1 the latest version is Cocos2d-x 3.2alpha0, readers can go to http://www.cocos2d-x.org/downloaddownload the latest version
- Python 3.4.0
- Xcode 5.1.1
- LDT (Lua Development Tools)
First use the terminal to enter the Directory:/Volumes/DATA/cocos2d-x-3.1.1/tools/cocos2d-console/bin and use cocos to create a project:
Run the command
Cocos. py new HelloCC-p com. wwj. hellocc-l lua-d ~ /Cocos2dxProj
Cocos2d-x 3. x and above use the cocos command to create a project, the command here means: Use the cocos. py script to upload a Lua project named HelloCC in the Cocos2dxProj folder under the root directory.
We can see that the HelloCC project structure, compared with the 2.x. x version, has undergone a huge change, and our corresponding platform project is here:
Open proj. ios_mac:
Double-click HelloCC. xcodeproj and use Xcode to open the project and compile and run the project. The shortcut key can be command + R:
Successful Lua projects:
Then use LDT to switch the workspace to HelloCC:
After switching the workspace, create a Lua project named src to include the Lua file in src in the Cocos2d-x, as shown in:
In this way, we can use LDT to write our Lua code.
The content of this blog has been completed, and the operation in Windows is similar. I will not talk about it here. The next blog will show you how to use Lua to develop a small game.