The relation between quick-cocos2d-x and cocos2d-x

Source: Internet
Author: User

Quick-cocos2d-x (hereinafter referred to as quick) and the relationship between cocos2d-x, with a word to summarize: Quick is cocos2d-x for Lua luxury Suit power enhanced version.


What is the difference between quick and cocos2d-x? This article is the answer:


Why is quick
Differences between quick and cocos2d-x
What components does quick consist?
Should you select Lua or JavaScript?
Quick Start


Why is quick
Cocos2d-x is a game engine developed with C ++, its architectural design and API is basically a copy of The cocos2d-iphone (an iOS game development engine with objective-C ).


Because c ++ has high requirements on developers, netlong uses tolua ++ as a tool, convert the C ++ interface of the cocos2d-x to the Lua interface (this library that exports the C ++ interface as the Lua interface is usually called luabinding ). Developers can use Lua, a simple and easy-to-understand scripting language, to write games, greatly improving development efficiency.


In the first half of 2012, our company began to use cocos2d-x + Lua to develop games. However, we found that there were quite a lot of imperfections in the support of Lua by cocos2d-x at that time. Therefore, I have rewritten the support code for the entire luabinding to solve problems such as memory leakage and the use of global functions for callback.


After the release of cocos2d-x 2.0, luabinding has made many improvements and improvements. As of cocos2d-x 2.1.4, the entire luabinding has been said to be quite stable. So "I am MT", "dazhangmen" These make money like printing money games, have adopted cocos2d-x + Lua solution.


Unfortunately, the cocos2d-x team has been vigorously promoting cocos2d-x's JavaScript solutions since 2012, so there is basically no major action in Lua support. From the perspective of our Lua solution developers, we need luabinding to have more powerful features, so this is the initial reason for us to develop quick.


Quick goals:


Learning Curve reduction
Improved usability
Create a streamlined but more scalable architecture


Differences between quick and cocos2d-x
Although cocos2d-x luabinding has been well developed, but to develop a game, we still need to do a lot of basic work.


It is the most basic task to encapsulate the C ++ interface exported by luabinding into a Lua-style interface. Re-encapsulated interfaces should be easier to learn and use, and some data format conversion between C ++ and Lua should also be hidden. This is the first goal of quick.


Take a look at the following code:


-- Load sprite Sheet
Local framecache = ccspriteframecache: sharedspriteframecache ()
Framecache: addspriteframeswithfile ("sprites. plist", "sprites.png ")


-- Construct an animation sequence run0001.png-> run0010.png
Local frames = ccarray: Create ()
For Index = 1, 10 do
Local framename = string. Format ("run000004d.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 an animation on ccsprite (10 frames are played in 0.5 seconds)
Local animation = ccanimation: createwithspriteframes (frames, 0.5/10)
Sprite: runaction (ccrepeatforever: Create (ccanimate: Create (animation )))
The functions of this Code are repeated in the game, so it is usually encapsulated into several simple functions. The following code is used to complete the same function of the encapsulated interface in quick:


Display. addspriteframeswithfile ("sprites. plist", "sprites.png ")
Local frames = display. newframes ("runner04d.png", 1, 10)
Local sprite = display. newspritewithframe (frames [1])
Local animation = display. newanimation (frames, 0.5/10)
Sprite: playanimationforever (animation)
Through this comparison, we can see how necessary secondary encapsulation is. Quick provides a Lua framework that encapsulates a large number of the most commonly used interfaces.


Cocos2d-x is a fully functional game engine, but for a game that can make money, cocos2d-x still lacks many necessary functions. So quick on the basis of cocos2d-x added more game functions, such as improved HTTP and Socket network functions, data encryption and decryption, device function access and so on.


When the gameplay is almost done, You need to integrate various third-party sdks, such as pay-as-you-go recharge, statistics, social sharing, and friend chains.


To do this on iOS and Android platforms, the traditional method is to write the objective-C and Java interface code respectively, and then use C ++ to transfer the code to Lua using tolua ++. This method is not only cumbersome, but also has many difficulties in interacting with C ++, so the development efficiency is extremely low.


To solve this problem, quick has developed two modules: luaobjectivecbridge and luajavabridge. With these two modules, we no longer need the C ++ intermediate layer or tolua ++ when accessing the SDK, which saves a staggering amount of work.


In addition, quick's ancillary projects provide a large number of off-the-shelf SDK packages to further improve development efficiency, allowing developers to spend their main resources on gameplay.


Continuous testing is required during the development process. While the cocos2d-x comes with Windows and Mac simulator function is too simple. Quick has developed a fully functional simulator, so that the entire game can be played most of the time in the development phase without using a real machine, android real machine debugging is so cool ).


Let's take a look at the gorgeous simulator of quick :)






In addition to the above content, quick also contains the Lua encapsulation of the physical engine chipmunk 2D (believe me, you cannot find a physical engine interface that is easier to use than this one), skeleton animation playback (support for dragonbones, cocostudio), high-performance luajit virtual machine, and so on.


To sum up, the main differences between quick and cocos2d-x are as follows:


More comprehensive Lua support, including a Lua framework for secondary encapsulation of C ++ Interfaces
Supplemented by a large number of cocos2d-x not available, but the features required by the game
To improve development efficiency, the objective-C and Java bridging modules and enhanced windows/MAC simulators are provided.
In addition to these major differences, quick has made some adjustments and improvements in details. And some important bugfix and valuable new features from the latest development branch of cocos2d-x (devel 3.0) will be ported to quick later.


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




What components does quick consist?
Quick consists of the following parts:


Cocos2d-x: currently based on cocos2d-x 2.1.4
Tolua ++: used to export the C ++ interface to the Lua script.
Luajit: the fastest Lua Virtual Machine
Cocos2d-x-extra: extended functions, including data encryption, network transmission, device function access, etc.
Chipmunk 2D: Physical engine, and corresponding cocos2d-x and Lua encapsulation Interface
Csarmature: A skeleton animation playing library that supports skeleton animation created by dragonbones and cocostudio
In addition, there are some Lua extensions:


Lua_extensions: Required Lua modules, including JSON, zlib, luafilesystem, and luasocket
Luajavabridge: A simple LUA-Java interactive interface that simplifies SDK Integration
Luaobjectivecbridge: simple LUA-objective-C interactive interface


Should you select Lua or JavaScript?
Currently, the cocos2d-x supports binding in two scripting languages. For my personal understanding, the respective situations are listed as follows:


Features Lua Javascript
Full access to cocos2d-x API yesyes
IOS platform yesyes
Android platform yesyes
Windows yesyes
Mac platform yesyes
Linux platform Yes * Yes
HTML5 platform Noyes
JIT supports yesyes
Compiled as byte code yesyes
Can bytecode decompile Nono?
High Performance
The workload of accessing the SDK is simple and complex.
Exporting custom C ++ classes is simple and complex
I pay the most attention to the following points:


Running Efficiency: When the JIT is available, the running efficiency of the bytecode compiled by luajit can be close to that of C. In IOS environments that do not support JIT, Lua is much more efficient than JavaScript ().


Easy expansion: Lua was designed as an embedded language during design. Therefore, it is quite easy to export a C/C ++ interface to Lua.


Source code protection: the bytecode compiled by luajit cannot be decompiled at present, because luajit does not directly convert the source code at, but implements many in-depth Optimizations to the source code. The size of the bytecode compiled by luajit is 1/3 of the size of the bytecode compiled by Lua. This shows the degree of optimization.


Objectively speaking, the biggest advantage of JavaScript binding is that a large number of JS front-end developers can easily get started and support the HTML5 platform. However, from the experience of mobile games, Lua's operational efficiency is an important advantage.




Quick Start
This article focuses on this part. The previous sections are advertisements :)




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 run it in the command line.


Important:


Table is a universal data structure in Lua, which can represent both an array and a name-value pair. This is the same as array in PHP. The only difference is that when table is used as an array, the subscript of the first element starts from 1.
Function is of the first-class type in Lua. That is to say, you can pass a function as a normal value. This is the same as other functional programming languages, such as JavaScript.
In Lua, table and retriable are used to implement object-oriented design. This mechanism is implemented after the C ++ object is exported to Lua.
Find out the difference between "." and ":" When defining methods and calling methods.


Try to modify and improve the examples of quick
Run the examples in the sample directory using quick-X-player (the simulator of quick liuko. Just press F5 (Press cmd + R on Mac) to refresh the simulator to see the effect (I have been touched by the Web Front-end shoes). It will take a few days to become a skilled engineer.


The most common problems:


What object does this method return?


Because quick encapsulates the C ++ interface twice, the objects returned by some framework methods are not necessarily clear. But most of them can be inferred from the method name:


Display. newsprite () create a ccsprite object
Display. newframes () Create an array containing multiple ccspriteframe objects
Ui. newimagemenuitem () create a ccimgemenuitem object
Ui. newmenu () Create ccmenu object
If you cannot see it, go to the Framework directory to flip the source code.


What does this method do?


First, find from the framework. If you cannot find it, go to the cocos2d-x. Not found, that is the cocos2d-x-extra or third-party Library provides the method. Here we strongly recommend sublime text, a super god Editor, to search the full text of Shenma.


Why is the code ineffective?


Whether it's Lua or quick, the current version is very stable. In this case, do not first doubt the language features or engines, but perform more tests to see how the problem actually occurs.


Where can I find help?


Currently, quick does not have a dedicated community, so if you want to seek help, the quickest way is QQ group: 284148017. Of course, no one will be there to answer questions all day long, so QQ groups are more about sharing experiences. In the future, quick will establish its own community for your convenience.




Familiar with cocos2d-x APIs
In essence, quick is an enhanced version of the cocos2d-x, so familiarity with cocos2d-x APIS is the basic requirement. Fortunately, cocos2d-x has a wealth of learning materials, even c ++ code, rewrite to Lua is also very simple, it is just the difference in syntax.


In this phase, you can use the coinflip example in quick to add more methods or functions. Coinflip already has a complete prototype of the game, so it can be used to independently develop the game when coinflip freely adds features.




Learning to use extended functions and third-party Lua extensions
Quick contains a wide range of extension libraries, from payment to network services. These functions are also required when the game changes from a project to a product. Therefore, mastering the extended functions can greatly improve the development efficiency and avoid repeated efforts.


When learning the extension function, you need to know which open-source project the extension function is developed based on to find targeted learning resources. For example, luasocket, luafilesystem, and other Lua extensions and chipmunk 2D physical engines. Their usage can be found on the websites of their respective projects.




Export your c ++ object to Lua
Sometimes you need to write some C ++ objects and export them to Lua for use. Refer to * In lib/cocos2dx_extra/extra/luabinding *. the tolua file converts the C/C ++ header file to the file required by tolua ++, and then compiles the file into the luabinding interface using the script included in quick.


You can refer to other related documents in the quick project wiki.




Integrate third-party sdks
Quick has a repository quick-cocos2d-x-plugins that contains some SDK interface files. You can easily integrate the SDK by referring to the sample/luajavabridge examples and these interface files.


In the future, quick will also provide more SDK interfaces and corresponding sample code.


-End-

From: http://blog.csdn.net/kaitiren/article/details/35276177

The relation between quick-cocos2d-x and cocos2d-x

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.