没有找到自动生成的,我是手动加进去的
写的较简陋
1.把下面的方法加到lua_cocos2dx_cocosbuilder_auto.cpp文件中,找到CCBAnimationManager的地方加进去就可以了
tolua_function(tolua_S, "setAnimationCompletedCallback", tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback);
static int tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback(lua_State* tolua_S)
{
if (NULL == tolua_S)
return 0;
int argc = 0;
cocosbuilder::CCBAnimationManager* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"cc.CCBAnimationManager",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<cocosbuilder::CCBAnimationManager*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 1)
{
#if COCOS2D_DEBUG >= 1
if(!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err))
goto tolua_lerror;
#endif
LUA_FUNCTION handler = toluafix_ref_function(tolua_S,2,0);
//ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, ScriptHandlerMgr::HandlerType::NODE);
LuaCCBAnimationWrapper* tmpCallback = new LuaCCBAnimationWrapper();
tmpCallback->setCallback(handler);
self->setAnimationCompletedCallback(tmpCallback, CC_CALLFUNC_SELECTOR(LuaCCBAnimationWrapper::animationCompletedCallback));
return 0;
}
luaL_error(tolua_S, "%s has wrong number of arguments: %d, was expecting %d\n", "cc.CCBAnimationManager:setAnimationCompletedCallback",argc, 1);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'tolua_cocos2d_CCBAnimationManager_setAnimationCompletedCallback'.",&tolua_err);
return 0;
#endif
}
2.实现LuaCCBAnimationWrapper文件
LuaCCBAnimationWrapper.h
#ifndef __LuaCCBanimationWrapper_H_
#define __LuaCCBanimationWrapper_H_
#include "cocos2d.h"
using namespace cocos2d;
using namespace std;
class LuaCCBAnimationWrapper : public cocos2d::Ref
{
public:
LuaCCBAnimationWrapper();
~LuaCCBAnimationWrapper();
void animationCompletedCallback();
void setCallback(unsigned nFuncID);
private:
CallFunc *pCCCallFunc;
unsigned int m_nFuncID;
};
#endif //__LuaCCBanimationWrapper_H_
LuaCCBAnimationWrapper.cpp
#include "LuaCCBAnimationWrapper.h"
#include "CCLuaEngine.h"
LuaCCBAnimationWrapper::LuaCCBAnimationWrapper()
:pCCCallFunc(NULL), m_nFuncID(0) {
}
LuaCCBAnimationWrapper::~LuaCCBAnimationWrapper() {
}
void LuaCCBAnimationWrapper::animationCompletedCallback() {
/**
//2.x
if (0 != m_nFuncID) {
CallFunc *CallFuncTmp = CallFunc::create(m_nFuncID);
CallFuncTmp->execute();
m_nFuncID = 0; //TODO 当动画循环播放时会报错,记得修改
}
**/
//3.x
if (0 != m_nFuncID){
LuaStack* stack = LuaEngine::getInstance()->getLuaStack();
stack->executeFunctionByHandler(m_nFuncID, 1);
m_nFuncID = 0; //TODO 当动画循环播放时会报错,记得修改
}
}
void LuaCCBAnimationWrapper::setCallback(unsigned int nFuncID) {
CCLOG("setCallback id: %i ", nFuncID);
m_nFuncID = nFuncID;
}
记得要在上一个文件lua_cocos2dx_cocosbuilder_auto.cpp中导入头文件引用
3.lua中要修改CCBReaderLoad.lua文件,无需大改动,只需将ccbReader加在返回值返回即可
4.然后在lua中可直接使用了
local animationManager = ccbReader:getActionManager()
animationManager:setAnimationCompletedCallback(function()
print("setAnimationCompletedCallback")
end)
本文介绍了在Cocos2d-x 3.3版本升级后,如何在lua中修改ccb动画完成的回调函数。主要内容包括在lua_cocos2dx_cocosbuilder_auto.cpp中添加新方法,实现LuaCCBAnimationWrapper类,并在lua脚本中调用新的回调功能。
4223

被折叠的 条评论
为什么被折叠?



