DragonBones For CocosLua

龙骨骼官方提供了一套cocos cpp的api,由于各平台API需要统一的缘故,这套API只适合cpp,不适合LUA导出,所以花了点时间重构一下,整了个luabind版

https://code.csdn.net/leezjl/dragonbonesforcocoslua/tree/master

为了方便向lua绑定,修改部分代码:
  • 所有继承自BaseObject的类对象,无论返回值还是函数参数,都改为指针形式,如:
    • BaseFactory::copyAnimationsToArmature(Armature* toArmature, …)
    • Animation* Armature::getAnimation()
  • 所有参数或者返回值为 void* 类型的函数,在lua中不可用,请用其他方法代替

使用:

将代码导入工程

cpp注册lua

#include "auto_dragonbones/lua_dragonbones_auto.hpp"
#include "auto_dragonbones/lua_dragonbones_manual.hpp"

register_all_dragonBones(L);
register_all_dragonbones_manual(L);

lua调用

function _:sf_frameEvent(eventName, armatureName, animationName)
    print("sf_frameEvent_callback", eventName, armatureName, animationName)
end

function _:sf_animationEvent(eventType, armatureName, animationName)
    print("animationEvent", eventType, armatureName, animationName)
end

local factory = db.CCFactory:getInstance()
factory:setArmaturePath("res/armatures")
factory:loadDataByName("sf")
local sf = factory:buildArmatureDisplay("armatureName", "sf")
sf:setPosition(display.designSize.center)
sf:setScale(.5)
-- 播放动作normalAttack 100遍
local animState = sf:getAnimation():gotoAndPlayByFrame("normalAttack", 0, 100)
-- 或者匿名函数的方式
--[[
sf:setFrameEventListener(function(eventName, armatureName, animationName)
    print(eventName, armatureName, animationName)
end)
]]
sf:setFrameEventListener(self, self.sf_frameEvent)
sf:setAnimationEventListener(self, self.sf_animationEvent)
-- 或者匿名函数的方式
--[[
sf:setAnimationEventListener(function(eventType, armatureName, animationName)
    print("animationEvent", eventType, armatureName, animationName)
end)
]]
-- 暂停当前动画
animState:stop()
-- 继续当前动画
animState:play()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值