[One of COCOS2DX-LUA Script Development] In cocos2dx game using Lua script for game development (basic) and introduce the script in the game for detailed purposes!

Source: Internet
Author: User

All articles on this site areLi huaming himiOriginal, reprinted must be explicitly noted:
Reprinted from[Heimi gamedev block]Link: http://www.himigame.com/iphone-cocos2dx/681.html

☞Click to subscribe☜
The latest developments in this blog! Notify you of the latest blog in time!

For gaming companies, it is also common to use game scripts such as Lua and python for development. However, many shoes are not very familiar with the concept of scripts, this article briefly introduces the usage of the script and its basic usage in cocos2dx;

For more information about Lua and python, see the Baidu encyclopedia. Lua and Python are two common scripting languages, lua is lightweight, and there are no more differences, but there are two reasons why Lua should be explained in this chapter: First, cocos2dx game engine embedded Lua, and second: since the fire of "Angry Birds", many domestic users prefer to use Lua =. =

Therefore, the usage of the script may be described as follows:

1. scripts are similar to the "brain" function in mobile games. All game-related logic code is generally stored in scripts, while the client (front-end) code belongs to the "body ", it can also be said that it is a "Player", which only serves to display the UI functions. In this case, scripts can not only be used, for example, map data;

2. script plays an important role in mobile online games. For example, if "himi" is not used in an online game, if "himi" 1.0 is released, it suddenly finds that the client has some tricky bugs to fix, if you want to modify it, you must wait for the client to be updated again and submit it again for release. This will result in the loss of a large number of users and the loss of some users for each game update; however, if the "himi" online game uses scripts, eazy can solve such problems. For example, all the logic code in the "himi" game is stored in script. in Lua, if. if there is a problem in the Lua logic, we can directly fix. the Lua script is updated to the server. Generally, the script defines the version number, for example,. lua has a bug version: 1.0. lua version is changed to 1.1. When you start the game each time, the client compares the version of the script with the version of the server script. When the server script version number is newer than the current script, it automatically goes down Load and overwrite the current script, OK, and solve the problem. This is not the case, for example, if you want to make an activity in the game or change an image, you can update it, instead of re-releasing a new game version every time you modify the front-end code, causing some losses!

OK, no more, next we will introduce some simple use of Lua script in cocos2dx, first we create a new Cocos2dx-lua template project, by default this template has an example, kids shoes can directly run the project to see the results, but everyone may be depressed that no related code can be found in the class ?!? That's right, because all the logic code is placed in the Lua script. After the project is started, a script named hello. Lua is parsed directly!

Open the resources of the project and find out whether there are two script files hello. Lua and hello2.lua ?! OK. So it's easier for me to talk about the example script of cocos2dx_lua demo here, but I'm certainly not familiar with my shoes, so himi has reorganized a simple example script code here, you can directly copy the following code to hello. the Code is as follows:

12345678910111213141516171819202122232425

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.