"Go" How to do dragonbones Lua binding (VisualStudio)

Source: Internet
Author: User

The original: "How to do dragonbones Lua binding (VisualStudio)"(imperfect and wrong place I have done red-letter modification)

Recently many students in the QQ group asked how to use DB (Drgonbones, keel) in the LUA project, in order to help more people, but also to let more people with easy to use DB, here detailed record coco2dx-3.2 version corresponding to the LUA binding of DB.

First of all, this article corresponds to the cocos2dx-3.2 version, the other cocos2dx-3.x version is similar to version 3.2.
This assumes that you are using the LUA project created by the Cocos Command line, and that you have not modified the directory structure, and if you modify it, find the directory where the specific files are located.

The first hypothesis, suppose you already know how to configure cocos2dx-3.x LUA bindings, if you don't know, please step bindings-generator to view the Readme file.
The second hypothesis is that you've created a LUA project with cocos2dx-3.2, with the name MyLuaGame , and not the path inside.

Download the Dragonbonescpp project from GitHub and dragonbones move the folder MyLuaGame/frameworks/cocos2d-x/cocos/editor-support down. The directory structure resembles this:

Add DB Library

Open the project in VS (Visual Studio) MyLuaGame .
Right-click 解决方案 = + Add + = Existing project ..., select myluagame/frameworks/cocos2d-x/cocos/editor-support/dragonbones/renderer/ Cocos2d-x-3.x/proj.win32/libdragonbones.vcxproj.

To add a preprocessing macro

libDragonbonesAdd preprocessing libluacocos2d macros to and from the library DRAGON_BONES_ENABLE_LUA=1 .
Right-click the libDragonbones = = Property = + Config Property = = C + + + + preprocessor = + Preprocessor definition, click on the value to the right there will be a drop-down box, select Edit, add DRAGON_BONES_ENABLE_LUA=1 and confirm.
Here is libDragonbones the preprocessing macro, libluacocos2d which is also similar.

There is also an easy way to configure predefined macros without having to go to the project to modify the myluagame/frameworks/cocos2d-x/cocos/editor-support/dragonbones/renderer/ Cocos2d-x-3.x/dbccmacro.h file,
#define DRAGON_BONES_ENABLE_LUA 0change the 0 in to 1.
However, it is not recommended to modify the source files of the DB directly, as it will need to be modified again in the future when DB is upgraded.

To libluacocos2dAdd two search paths to the library

Right- libluacocos2d Click the = = Property = + Config property = = C/c++=> General + Add included directory, click on the value to the right there will be a drop-down box, select Edit, add the following search path and confirm.

$(engineroot)Cocos\Editor-support\dragonbones$(engineroot )Cocos\Editor-support\dragonbones\renderer\ Cocos2d-x-3.x             
Add a dependency for Myluagame

Right-click MyLuaGame = = Generate dependencies = = Project Dependencies ..., check libDragonbones .
Right-click = = Properties = = MyLuaGame General Properties = = Add New references libDragonbones

Modify Conversions.yaml

File path: Myluagame/frameworks/cocos2d-x/tools/bindings-generator/targets/lua/conversions.yaml

ns_map:Under Add"dragonBones::": "db."

to_native:Add the following:

:"${out_value} =  toluafix_ref_function (tolua_s,${arg_idx},0); OK &= ${out_value}! = 0;"

Full file Download (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4), please modify the other version.

Add Dragonbones.ini

File path: Myluagame/frameworks/cocos2d-x/tools/tolua/dragonbones.ini

Copy the Cocos2dx.ini and name it Dragonbones.ini.
Refer to the Dragonbones.ini modification of cocos2dx-3.2.

  1. Modify the first line [cocos2d-x] = =[dragonbones]
  2. Modify + prefix = cocos2dx =prefix = dragonbones
  3. Modify + target_namespace = cc =target_namespace = db
  4. Append the following paths to cocos_headers, space-delimited, and not wrapped.
    -I%(Cocosdir)S/Cocos/Editor-Support/Dragonbones-I%(Cocosdir)S/Cocos/Editor-Support/Dragonbones/Renderer/Cocos2d-X-3.x-I%(Cocosdir)S/external/lua/luajit< Span class= "pun" >/include-i% ( cocosdir) s/cocos< Span class= "pun" >/scripting/lua-bindings/manual-i % (cocosdirs/ external/lua/tolua   
  5. Set the following header file to headers, directly overwrite the original is good, still space-delimited, cannot wrap.
    %(Cocosdir)S/Cocos/editor-support/< Span class= "PLN" >dragonbones/renderer/ Cocos2d-x-3.x/dbccrenderheaders.% (cocosdirs/cocos/editor-support/dragonbones/dragonbonesheaders h                
  6. Add the following classes to the classess, you can overwrite the original is good, still space-delimited, cannot wrap. You can add more classes that you need yourself.
    DbccarmaturedbccarmaturenodearmatureAnimationanimationstatedbccfactorybasefactory Slotdbccslotworldclockianimatable         
  7. Set skip to the following, note the format, you can modify it yourself.
    Skip= Bone::[getslots getchildarmature], armature< Span class= "pun" >::[getslots getbones getboundingbox], animation::[getanimationdatalist setanimationdatalist Getanimationdata addLayer setactive], slot ::[setdisplaylist getdisplaylist getboundingbox  basefactory::[gettextureatlasmap Getdragonbonesdatamap], worldclock::[< Span class= "PLN" >add remove Contains]          
  8. Set the abstract_classes as below, and the direct overlay is good.
    =basefactoryslotarmatureianimatablebasefactoryslotarmatureianimatable 

Full file Download (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4), please modify the other version.

Modify genbindings.py

File path: myluagame/frameworks/cocos2d-x/tools/tolua/genbindings.py

Search ‘cocos2dx.ini‘ : (‘cocos2d-x‘, ‘lua_cocos2dx_auto‘) ,
Added in this section ‘dragonbones.ini‘ : (‘dragonbones‘, ‘lua_dragonbones_auto‘), .
The complete code snippet is:

Cmd_args= {' Cocos2dx.ini ' : (' Cocos2d-x ', ' Lua_cocos2dx_auto '), \ ' Cocos2dx_extension.ini ' : (' Cocos2dx_extension ', ' Lua_cocos2dx_extension_auto '), ' Cocos2dx_ui.ini ' : (' COCOS2DX_UI ', ' Lua_cocos2dx_ui_auto '), ' Cocos2dx_studio.ini ' : (' Cocos2dx_studio ', ' Lua_cocos2dx_studio_auto '), ' Cocos2dx_spine.ini ' : (' Cocos2dx_spine ', ' Lua_cocos2dx_spine_auto '), ' Cocos2dx_physics.ini ' : (' Cocos2dx_physics ', ' Lua_cocos2dx_physics_auto '), ' Cocos2dx_experimental_video.ini ' : (' Cocos2dx_experimental_video ', ' Lua_cocos2dx_experimental_video_auto '), ' Cocos2dx_experimental.ini ' : (' Cocos2dx_experimental ',  ' Lua_cocos2dx_experimental_auto ' ),   Cocos2dx_controller.ini '  :  ( ' Cocos2dx_controller ' ,  ' Lua_cocos2dx_controller_auto ' Span class= "pun"), \  ' Dragonbones.ini '  :< Span class= "PLN" >  ( ' dragonbones ' ,  ' Lua_dragonbones_auto ' \  } target =  ' LUA '   

Full file Download (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4), please modify the other version.

Generate LUA Bindings

Because the cocos2dx-3.2 version of the LUA binding is missing dos2unix.exe files, it needs to be downloaded from here and put in
The Myluagame/frameworks/cocos2d-x/tools/bindings-generator/tools/win32 directory.
Run on the command line MyLuaGame/frameworks/cocos2d-x/tools/tolua/genbindings.py , the build succeeds only once.

If you are not configured or have not successfully generated the binding file, you can download the full binding file yourself, other versions of the self-modification.
LUA_DRAGONBONES_AUTO.HPP (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4)
Lua_dragonbones_auto.cpp (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4)

Register Libdragonbones tolibluacocos2d

Right-click libluacocos2d/auto = + Add = Existing Item:, select the lua_dragonbones_auto.cpp and file under the myluagame/frameworks/cocos2d-x/cocos/scripting/lua-bindings/auto/directory. lua_dragonbones_auto.hpp

CCLuaStack.cppadds a header to the #include "lua_dragonbones_auto.hpp" .
Add to the bool LuaStack::init(void) function register_all_dragonbones(_state); .

Full file Download (cocos2dx3.2, cocos2dx3.3, cocos2dx3.4), please modify the other version.

At last

It's all over here, the project should be compiled and run, and then write the code in LUA.

If MyLuaGame the C + + section also uses Dragonbones, you also need to add search paths and predefined macros for the Myluagame project.

"Go" How to do dragonbones Lua binding (VisualStudio)

Related Article

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.