The difference between Quick-cocos2d-x and COCOS2DX

Source: Internet
Author: User
Tags extend lua web services sublime text advantage
Quick-cocos2d-x (hereinafter referred to as quick) and Cocos2d-x's relationship, in a nutshell: Quick is cocos2d-x for Lua's luxury suite power-enhanced version.


Project Address: Quick-cocos2d-x Project Wiki:wiki


What is the difference between quick and cocos2d-x, and what is there to strengthen it? This article is the answer:


Why would there be quick?
The difference between quick and cocos2d-x
Which parts of quick are made up
Should I choose Lua or JavaScript?
How to get started quick


Why would there be quick?
Cocos2d-x is a game engine developed in C + +, and its architectural design and API are basically copied Cocos2d-iphone (a objective-c IOS game development engine).


Since C + + has a high demand for developers, the tolua++ technology uses this tool to turn Cocos2d-x's C + + interface into a LUA interface (a library that exports C + + interfaces to LUA interfaces is often referred to as luabinding). It allows developers to write games in a simple, easy-to-understand scripting language, which greatly improves development efficiency.


Probably in the first half of 2012, our company started using Cocos2d-x + Lua to develop games. However, it was found that there were quite a few imperfections in Cocos2d-x's support for Lua. So I rewrote the entire luabinding support code, resolving memory leaks, only using global functions to do callbacks, and so on.


After the release of Cocos2d-x 2.0, Luabinding also made a lot of improvement and improvement. By the end of Cocos2d-x 2.1.4, the whole luabinding has been said to be quite stable. So "I am MT", "Big masters" these money like printing money games, have adopted cocos2d-x + Lua solution.


Unfortunately the Cocos2d-x team has been aggressively promoting Cocos2d-x's JavaScript solution since 2012, so there's basically nothing big on Lua support. And from the developers of our Lua solutions, we need luabinding to have more powerful features, so this is the first reason we developed the quick.


Quick's goal:


Reduce the learning curve
Improved ease of Use
Create a streamlined, but easier to scale architecture


The difference between quick and cocos2d-x
Although Cocos2d-x luabinding is perfect, we need to do a lot of basic work to develop a game.


Re-encapsulating the luabinding exported C + + interface into a Lua-style interface is the most basic work. The re-encapsulated interface should be easier to learn and use, and some data format conversions between C + + and Lua should be hidden. And that's the first goal in quick.


Take a look at the following code:


--Loading Sprite Sheet
Local Framecache = Ccspriteframecache:sharedspriteframecache ()
Framecache:addspriteframeswithfile ("Sprites.plist", "Sprites.png")


--Construction of a frame animation sequence Run0001.png-Run0010.png
Local frames = Ccarray:create ()
For index = 1, ten do
Local framename = String.Format ("run%04d.png", Index)
Local frame = Framecache:spriteframebyname (framename)
Frames:addobject (frame)
End


--Create a Ccsprite object
Local firstframe = Tolua.cast (Frames:objectatindex (0), "Ccspriteframe")
Local Sprite = Ccsprite:createwithspriteframe (firstframe)


--Play animations over Ccsprite (10 frames in 0.5 seconds)
Local animation = Ccanimation:createwithspriteframes (frames, 0.5/10)
Sprite:runaction (Ccrepeatforever:create (ccanimate:create (animation)))
The functionality of this code is repeated in the game, so it is usually encapsulated into a few simple functions. The following code is used to perform the same function as the interface in the Quick package:


Display.addspriteframeswithfile ("Sprites.plist", "Sprites.png")
Local frames = Display.newframes ("Run%04d.png", 1, 10)
Local Sprite = Display.newspritewithframe (frames[1])
Local animation = Display.newanimation (frames, 0.5/10)
Sprite:playanimationforever (animation)
By this comparison, it can be seen how necessary two times the package. And Quick provides a Lua Framework that encapsulates a number of the most commonly used interfaces.


Cocos2d-x is a full-featured game engine, but for a game that can make money, cocos2d-x still lacks a lot of necessary features. So quick adds more features to the game based on Cocos2d-x, such as Perfect HTTP and Socket network functions, data encryption and decryption, device function access, and more.


Game play is done almost, you need to start to integrate the payment recharge, statistics, social sharing, friend chain and other third-party SDK.


To do this on IOS and Android, the traditional practice is to write objective-c and Java interface code separately, then in C + +, and export it to Lua using tolua++. This approach is cumbersome, and there are considerable difficulties in interacting with Java and C + +, so development efficiency is extremely low.


For this issue, Quick has developed two modules for Luaobjectivecbridge and Luajavabridge. With these two modules, when we access the SDK, we no longer need the C + + transit layer, and do not need to tolua++, thus saving a lot of work.


and Quick's affiliate program provides a large number of ready-made SDK packages to further improve development efficiency and allow developers to spend their major resources on gameplay.


During the development process, continuous testing is required. The Windows and Mac simulator features that cocos2d-x comes with are too simple. Quick has developed a fully functional simulator that allows the entire game to be carried out without the need for a real machine for most of the development phase (as the small partners know, the real-time Android debugging is so painful).


Look at the quick, gorgeous simulator:)






In addition to the above, quick also contains the physical engine Chipmunk 2D Lua package (believe me, you can not find more than this easier to use physics engine interface), bone animation playback (support Dragonbones, Cocostudio), high-performance Luajit Virtual machines and so on.


In summary, the main differences between quick and cocos2d-x are as follows:


More complete LUA support, including a LUA framework that encapsulates the C + + interface two times
Added a lot of cocos2d-x not provided, but the game needs the features
For increased development efficiency, OBJECTIVE-C and Java bridging modules are available, as well as enhanced WINDOWS/MAC simulators
In addition to these important differences, quick also made some adjustments and improvements in the details. Some important bugfix and valuable new features from Cocos2d-x's newest development branch (Devel 3.0) will also be ported to quick.


Of course, when the Cocos2d-x 3.0 is completely stable, quick will also do the corresponding upgrade.




Which parts of quick are made up
Quick is made up of several main parts:


Cocos2d-x: Currently based on Cocos2d-x 2.1.4 version
tolua++: Used to export a C + + interface to a Lua script
Luajit: Fastest Lua virtual machine
Cocos2d-x-extra: Extended functions, including data encryption and encoding, network transmission, device function access, etc.
Chipmunk: Physics engine, and corresponding cocos2d-x and Lua encapsulation interfaces
Csarmature: A skeleton animation library that supports skeletal animations created by Dragonbones and Cocostudio
In addition, some of the Lua extensions are included:


Lua_extensions: Some of the necessary Lua modules, including JSON, ZLib, Luafilesystem, Luasocket, etc.
Luajavabridge: Simple Lua-java interface simplifies SDK integration
Luaobjectivecbridge: simple Lua-objective-c Interactive interface


Should I choose Lua or JavaScript?
Currently Cocos2d-x supports the binding of two scripting languages, and from my own knowledge, the respective case list is as follows:


Features Lua JavaScript
Full access to Cocos2d-x API Yes Yes
IOS platform Yes Yes
Android platform Yes Yes
Windows platform Yes Yes
MAC platform Yes Yes
Linux Platform yes* YES
HTML5 Platform NO YES
JIT Support Yes Yes
Compile to byte code Yes Yes
Whether bytecode can be decompile no no
Operating Performance Low
Access SDK workload is simple and complex, through C + + Transit
Exporting custom C + + classes is simple and complex
And I value a few of them:


Operating efficiency: Luajit compiled bytecode when JIT is available, the efficiency of the operation can be close to the degree of C. In the case of IOS, which does not support JIT, Lua runs much more efficiently than JavaScript ().


It is easy to extend: Lua is designed as an embedded language from design time, so it is quite easy to export a C/s + + interface to LUA for use.


Source code protection: Luajit compiled bytecode is currently not decompile, because Luajit at compile time is not 1:1 direct conversion source code, but the source code to do a lot of deep optimization. Luajit compiled bytecode volume is one-third of Lua compiled bytecode, which shows the degree of optimization.


Objectively speaking, the biggest advantage of JavaScript binding is that before a large number of JS front-end developers can easily get started, and support HTML5 platform. However, the efficiency of Lua is an important advantage in terms of the hand travel experience.




How to get started quick
Things are good, learning will not be useless, so the focus of this article is this part, the front is advertising:)




Learn Lua
Lua is an easy-to-use language. The best way to learn this language is to spend a few days writing code and then running it on the command line.


Focus:


Table is a universal data structure in Lua that can represent both arrays and name-value pairs. This is the same as the array in PHP. The only difference is that when table is used as an array, the subscript of the first element starts at 1.
function is a first-class type in Lua, meaning you can pass a function as a normal value, which is the same as other functional programming languages, such as JavaScript.
Lua implements object-oriented with table mates with MetaTable. Since C + + objects are exported to Lua, this is the mechanism, so this must be understood.
Figure out how to define the method and invoke the method, using "." and ":" The difference.


Sample programs that try to modify and refine quick
Use the Quick-x-player (the simulator of the Quick Bull Fork) to run all the examples in the sample directory without differential detonation. To change a little, press F5 (Mac on cmd+r) to refresh the emulator to see the effect (done the Web front-end of the children's shoes touched it), in a few days will become skilled workers.


Most frequently encountered problems:


This method returns an object.


Because quick encapsulates the C + + interface two times, some framework methods return objects that are not necessarily explicit. But most can be inferred from the method name:


Display.newsprite () Create Ccsprite Object
Display.newframes () creates an array that contains multiple Ccspriteframe objects
Ui.newimagemenuitem () Create Ccimgemenuitem Object
Ui.newmenu () Create Ccmenu Object
Really can't see, then go to the framework directory to turn over the source code bar.


This is the way to do it.


First, look in the framework. If you can't find it, go to the cocos2d-x. Not found, that is the method provided by Cocos2d-x-extra or third-party libraries. It is highly recommended that the Sublime text of this super-God editor, full-text search of God horse completely.


Why the code does not have the expected effect.


Whether it's Lua or quick, the current version is very, very stable. So in this case, don't first doubt the language features or the engine, but do more testing to see how the problem is happening.


Where to ask for help.


There is no dedicated community for quick, so if you are looking for help, the quickest way is QQ group: 284148017. Of course, there will be no one all day in the obligation to answer, so QQ group More is a place to exchange experience. In the future, quick will establish its own community and facilitate the exchange of people.




Familiarity with the Cocos2d-x API
In essence, quick is an enhanced version of Cocos2d-x, so familiarity with the Cocos2d-x API is a basic requirement. Fortunately Cocos2d-x now has a wealth of learning materials, even the C + + code, rewritten as Lua is very simple, but also the difference between the syntax.


This stage can be based on the Coinflip example in quick, adding more gameplay or functionality. Coinflip already has the embryonic form of a complete game, so when you can add functionality in Coinflip, it is possible to develop the game independently.




Learn to use extension features and third-party Lua extensions
Quick includes a rich library of extensions, ranging from payment to Web services. These functions are also necessary for the game to become a product from the project, so the ability to master the extended function can greatly improve the development efficiency and avoid duplication of work.


When learning to extend the functionality, learn how this extension is developed based on what open source projects are available to find targeted learning resources. For example, Lua extensions such as Luasocket, Luafilesystem, Chipmunk 2D physics engines, and so on, their usage is found on the website of their respective projects.




Export your own C + + objects to Lua
Sometimes it is necessary to write some C + + objects and then export them to Lua. Here you can refer to the *.tolua file in the lib/cocos2dx_extra/extra/luabinding, convert the C + + header file to the tolua++ required file, and compile the Luabinding interface with the script included with the quick.


In the quick Project Wiki, there are other related documents that you can refer to.




Integration with third-party SDKs
Quick has a secondary repository quick-cocos2d-x-plugins, which contains some SDK interface files. Referring to the Sample/luajavabridge sample and these interface files, it is easy to complete the integration of the SDK.


Subsequent quick will also provide additional SDK interfaces, along with the corresponding sample code.


-END-

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.