mirror of https://github.com/axmolengine/axmol.git
1. add Spine LUA binding with testcase; 2. CCSkeleton inherites from Node since NodeRGBA is deprecated.
This commit is contained in:
parent
a9f014eb22
commit
4082c86070
|
@ -42,7 +42,7 @@ namespace spine {
|
|||
/**
|
||||
Draws a skeleton.
|
||||
*/
|
||||
class CCSkeleton: public cocos2d::NodeRGBA, public cocos2d::BlendProtocol {
|
||||
class CCSkeleton: public cocos2d::Node, public cocos2d::BlendProtocol {
|
||||
public:
|
||||
spSkeleton* skeleton;
|
||||
spBone* rootBone;
|
||||
|
|
|
@ -15,12 +15,15 @@ LOCAL_SRC_FILES := CCLuaBridge.cpp \
|
|||
LuaOpengl.cpp \
|
||||
LuaScriptHandlerMgr.cpp \
|
||||
LuaBasicConversions.cpp \
|
||||
LuaSkeletonAnimation.cpp \
|
||||
../../auto-generated/lua-bindings/lua_cocos2dx_auto.cpp \
|
||||
../../auto-generated/lua-bindings/lua_cocos2dx_extension_auto.cpp \
|
||||
../../auto-generated/lua-bindings/lua_cocos2dx_studio_auto.cpp \
|
||||
../../auto-generated/lua-bindings/lua_cocos2dx_spine_auto.cpp \
|
||||
lua_cocos2dx_manual.cpp \
|
||||
lua_cocos2dx_extension_manual.cpp \
|
||||
lua_cocos2dx_coco_studio_manual.cpp \
|
||||
lua_cocos2dx_spine_manual.cpp \
|
||||
lua_cocos2dx_deprecated.cpp \
|
||||
lua_xml_http_request.cpp \
|
||||
platform/android/CCLuaJavaBridge.cpp \
|
||||
|
@ -39,6 +42,7 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../external/lua/tolua \
|
|||
$(LOCAL_PATH)/../../../../extensions \
|
||||
$(LOCAL_PATH)/../../../editor-support/cocosbuilder \
|
||||
$(LOCAL_PATH)/../../../editor-support/cocostudio \
|
||||
$(LOCAL_PATH)/../../../editor-support/spine \
|
||||
$(LOCAL_PATH)/../../../gui
|
||||
|
||||
|
||||
|
@ -52,6 +56,7 @@ LOCAL_WHOLE_STATIC_LIBRARIES += websockets_static
|
|||
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES += spine_static
|
||||
|
||||
LOCAL_CFLAGS += -Wno-psabi
|
||||
LOCAL_EXPORT_CFLAGS += -Wno-psabi
|
||||
|
@ -65,3 +70,4 @@ $(call import-module,websockets/prebuilt/android)
|
|||
$(call import-module,network)
|
||||
$(call import-module,editor-support/cocostudio)
|
||||
$(call import-module,editor-support/cocosbuilder)
|
||||
$(call import-module,editor-support/spine)
|
||||
|
|
|
@ -56,6 +56,8 @@ extern "C" {
|
|||
#include "lua_xml_http_request.h"
|
||||
#include "lua_cocos2dx_studio_auto.hpp"
|
||||
#include "lua_cocos2dx_coco_studio_manual.hpp"
|
||||
#include "lua_cocos2dx_spine_auto.hpp"
|
||||
#include "lua_cocos2dx_spine_manual.hpp"
|
||||
|
||||
namespace {
|
||||
int lua_print(lua_State * luastate)
|
||||
|
@ -151,6 +153,8 @@ bool LuaStack::init(void)
|
|||
register_all_cocos2dx_extension_manual(_state);
|
||||
register_all_cocos2dx_manual_deprecated(_state);
|
||||
register_all_cocos2dx_coco_studio_manual(_state);
|
||||
register_all_cocos2dx_spine(_state);
|
||||
register_all_cocos2dx_spine_manual(_state);
|
||||
register_glnode_manual(_state);
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
|
||||
LuaObjcBridge::luaopen_luaoc(_state);
|
||||
|
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* LuaSkeletonAnimation.cpp
|
||||
*
|
||||
* Created on: 2013?11?21?
|
||||
* Author: edwardzhou
|
||||
*/
|
||||
|
||||
#include "LuaSkeletonAnimation.h"
|
||||
#include "cocos2d.h"
|
||||
#include "LuaScriptHandlerMgr.h"
|
||||
#include "CCLuaStack.h"
|
||||
#include "CCLuaEngine.h"
|
||||
|
||||
using namespace spine;
|
||||
USING_NS_CC;
|
||||
|
||||
//LuaSkeletonAnimation::LuaSkeletonAnimation() {
|
||||
// // TODO Auto-generated constructor stub
|
||||
//}
|
||||
|
||||
static int SendSpineEventToLua(int nHandler, CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
if (nHandler <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (NULL == ScriptEngineManager::getInstance()->getScriptEngine()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
LuaStack *pStack = LuaEngine::getInstance()->getLuaStack();
|
||||
if (NULL == pStack) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
lua_State *tolua_s = pStack->getLuaState();
|
||||
if (NULL == tolua_s) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int nRet = 0;
|
||||
|
||||
spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex);
|
||||
std::string animationName = (entry && entry->animation) ? entry->animation->name : "";
|
||||
std::string eventType = "";
|
||||
|
||||
switch (type) {
|
||||
case ANIMATION_START:
|
||||
//CCLOG("%d start: %s", trackIndex, animationName.c_str());
|
||||
eventType = "start";
|
||||
break;
|
||||
case ANIMATION_END:
|
||||
//CCLOG("%d end: %s", trackIndex, animationName.c_str());
|
||||
eventType = "end";
|
||||
break;
|
||||
case ANIMATION_COMPLETE:
|
||||
//CCLOG("%d complete: %s, %d", trackIndex, animationName.c_str(), loopCount);
|
||||
eventType = "complete";
|
||||
break;
|
||||
case ANIMATION_EVENT:
|
||||
//CCLOG("%d event: %s, %s: %d, %f, %s", trackIndex, animationName.c_str(), event->data->name, event->intValue, event->floatValue, event->stringValue);
|
||||
eventType = "event";
|
||||
break;
|
||||
}
|
||||
|
||||
LuaValueDict spineEvent;
|
||||
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("type", LuaValue::stringValue(eventType)));
|
||||
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("trackIndex", LuaValue::intValue(trackIndex)));
|
||||
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("animation", LuaValue::stringValue(animationName)));
|
||||
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("loopCount", LuaValue::intValue(loopCount)));
|
||||
|
||||
if (NULL != event) {
|
||||
LuaValueDict eventData;
|
||||
eventData.insert(eventData.end(), LuaValueDict::value_type("name", LuaValue::stringValue(event->data->name)));
|
||||
eventData.insert(eventData.end(), LuaValueDict::value_type("intValue", LuaValue::intValue(event->intValue)));
|
||||
eventData.insert(eventData.end(), LuaValueDict::value_type("floatValue", LuaValue::floatValue(event->floatValue)));
|
||||
eventData.insert(eventData.end(), LuaValueDict::value_type("stringValue", LuaValue::stringValue(event->stringValue)));
|
||||
spineEvent.insert(spineEvent.end(), LuaValueDict::value_type("eventData", LuaValue::dictValue(eventData)));
|
||||
}
|
||||
|
||||
// pStack->pushString(eventType.c_str());
|
||||
// pStack->pushInt(trackIndex);
|
||||
// pStack->pushString(animationName.c_str());
|
||||
// pStack->pushInt(loopCount);
|
||||
pStack->pushLuaValueDict(spineEvent);
|
||||
nRet = pStack->executeFunctionByHandler(nHandler, 1);
|
||||
pStack->clean();
|
||||
return nRet;
|
||||
|
||||
}
|
||||
|
||||
LuaSkeletonAnimation::LuaSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale)
|
||||
: CCSkeletonAnimation(skeletonDataFile, atlasFile, scale) {
|
||||
CCLOG("LuaSkeletonAnimation::LuaSkeletonAnimation");
|
||||
this->setAnimationListener(this, animationStateEvent_selector(LuaSkeletonAnimation::animationStateEvent));
|
||||
}
|
||||
|
||||
|
||||
LuaSkeletonAnimation::~LuaSkeletonAnimation() {
|
||||
ScriptHandlerMgr::getInstance()->removeObjectAllHandlers((void*)this);
|
||||
}
|
||||
|
||||
LuaSkeletonAnimation* LuaSkeletonAnimation::createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale) {
|
||||
LuaSkeletonAnimation* node = new LuaSkeletonAnimation(skeletonDataFile, atlasFile, scale);
|
||||
node->autorelease();
|
||||
return node;
|
||||
}
|
||||
|
||||
void LuaSkeletonAnimation::animationStateEvent (CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount) {
|
||||
|
||||
int nHandler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, static_cast<ScriptHandlerMgr::HandlerType>(SCRIPT_SPINE_EVENT));
|
||||
if (0 != nHandler) {
|
||||
SendSpineEventToLua(nHandler, node, trackIndex, type, event, loopCount);
|
||||
}
|
||||
|
||||
// spTrackEntry* entry = spAnimationState_getCurrent(node->state, trackIndex);
|
||||
// std::string animationName = (entry && entry->animation) ? entry->animation->name : "";
|
||||
// std::string eventType = "";
|
||||
//
|
||||
// switch (type) {
|
||||
// case ANIMATION_START:
|
||||
// //CCLOG("%d start: %s", trackIndex, animationName.c_str());
|
||||
// eventType = "start";
|
||||
// break;
|
||||
// case ANIMATION_END:
|
||||
// //CCLOG("%d end: %s", trackIndex, animationName.c_str());
|
||||
// eventType = "end";
|
||||
// break;
|
||||
// case ANIMATION_COMPLETE:
|
||||
// //CCLOG("%d complete: %s, %d", trackIndex, animationName.c_str(), loopCount);
|
||||
// eventType = "complete";
|
||||
// break;
|
||||
// case ANIMATION_EVENT:
|
||||
// //CCLOG("%d event: %s, %s: %d, %f, %s", trackIndex, animationName.c_str(), event->data->name, event->intValue, event->floatValue, event->stringValue);
|
||||
// eventType = "event";
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// int nHandler = ScriptHandlerMgr::getInstance()->getObjectHandler((void*)this, static_cast<ScriptHandlerMgr::HandlerType>(SCRIPT_SPINE_EVENT));
|
||||
// if (0 != nHandler) {
|
||||
// SendSpineEventToLua(nHandler, eventType, trackIndex, animationName, loopCount);
|
||||
// LuaValueDict eventData;
|
||||
// eventData.begin
|
||||
// }
|
||||
//fflush(stdout);
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* LuaSkeletonAnimation.h
|
||||
*
|
||||
* Created on: 2013?11?21?
|
||||
* Author: edwardzhou
|
||||
*/
|
||||
|
||||
#ifndef LUASKELETONANIMATION_H_
|
||||
#define LUASKELETONANIMATION_H_
|
||||
#include "spine/spine-cocos2dx.h"
|
||||
|
||||
#define SCRIPT_SPINE_EVENT 10001
|
||||
|
||||
class LuaSkeletonAnimation: public spine::CCSkeletonAnimation {
|
||||
private:
|
||||
void animationStateEvent (spine::CCSkeletonAnimation* node, int trackIndex, spEventType type, spEvent* event, int loopCount);
|
||||
|
||||
public:
|
||||
static LuaSkeletonAnimation* createWithFile (const char* skeletonDataFile, const char* atlasFile, float scale = 1);
|
||||
|
||||
LuaSkeletonAnimation (const char* skeletonDataFile, const char* atlasFile, float scale = 1);
|
||||
|
||||
//LuaSkeletonAnimation();
|
||||
virtual ~LuaSkeletonAnimation();
|
||||
};
|
||||
|
||||
#endif /* LUASKELETONANIMATION_H_ */
|
|
@ -0,0 +1,326 @@
|
|||
#include "lua_cocos2dx_spine_manual.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "tolua_fix.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "LuaBasicConversions.h"
|
||||
#include "LuaScriptHandlerMgr.h"
|
||||
#include "CCLuaValue.h"
|
||||
#include "spine.h"
|
||||
#include "spine-cocos2dx.h"
|
||||
#include "LuaSkeletonAnimation.h"
|
||||
|
||||
using namespace spine;
|
||||
|
||||
// setBlendFunc
|
||||
template<class T>
|
||||
static int tolua_cocos2dx_setBlendFunc(lua_State* tolua_S,const char* className)
|
||||
{
|
||||
if (NULL == tolua_S || NULL == className || strlen(className) == 0)
|
||||
return 0;
|
||||
|
||||
int argc = 0;
|
||||
T* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertype(tolua_S,1,className,0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
self = static_cast<T*>(tolua_tousertype(tolua_S,1,0));
|
||||
|
||||
argc = lua_gettop(tolua_S) - 1;
|
||||
if (2 == argc)
|
||||
{
|
||||
GLenum src, dst;
|
||||
if (!luaval_to_int32(tolua_S, 2, (int32_t*)&src))
|
||||
return 0;
|
||||
|
||||
if (!luaval_to_int32(tolua_S, 3, (int32_t*)&dst))
|
||||
return 0;
|
||||
|
||||
BlendFunc blendFunc = {src, dst};
|
||||
self->setBlendFunc(blendFunc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
CCLOG("'setBlendFunc' has wrong number of arguments: %d, was expecting %d\n", argc, 2);
|
||||
return 0;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'setBlendFunc'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int lua_cocos2dx_CCSkeletonAnimation_createWithFile(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0 ;
|
||||
|
||||
int argc = 0;
|
||||
CCSkeletonAnimation* self = nullptr;
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_Error tolua_err;
|
||||
if (!tolua_isusertable(L,1,"CCSkeletonAnimation",0,&tolua_err)) goto tolua_lerror;
|
||||
#endif
|
||||
|
||||
argc = lua_gettop(L) - 1;
|
||||
|
||||
if (2 == argc)
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isstring(L, 2, 0, &tolua_err) ||
|
||||
!tolua_isstring(L, 3 ,0, &tolua_err))
|
||||
{
|
||||
goto tolua_lerror;
|
||||
}
|
||||
#endif
|
||||
const char* skeletonDataFile = tolua_tostring(L, 2, "");
|
||||
const char* atlasFile = tolua_tostring(L, 3, "");;
|
||||
|
||||
auto tolua_ret = LuaSkeletonAnimation::createWithFile(skeletonDataFile, atlasFile);
|
||||
|
||||
int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1;
|
||||
int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL;
|
||||
toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"CCSkeletonAnimation");
|
||||
return 1;
|
||||
} else if (3 == argc)
|
||||
{
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
if (!tolua_isstring(L, 2, 0, &tolua_err) ||
|
||||
!tolua_isstring(L, 3 ,0, &tolua_err) ||
|
||||
!tolua_isnumber(L, 4 ,0, &tolua_err))
|
||||
{
|
||||
goto tolua_lerror;
|
||||
}
|
||||
#endif
|
||||
const char* skeletonDataFile = tolua_tostring(L, 2, "");
|
||||
const char* atlasFile = tolua_tostring(L, 3, "");
|
||||
LUA_NUMBER scale = tolua_tonumber(L, 4, 1);
|
||||
|
||||
auto tolua_ret = LuaSkeletonAnimation::createWithFile(skeletonDataFile, atlasFile, scale);
|
||||
|
||||
int nID = (tolua_ret) ? (int)tolua_ret->_ID : -1;
|
||||
int* pLuaID = (tolua_ret) ? &tolua_ret->_luaID : NULL;
|
||||
toluafix_pushusertype_ccobject(L, nID, pLuaID, (void*)tolua_ret,"CCSkeletonAnimation");
|
||||
return 1;
|
||||
}
|
||||
|
||||
CCLOG("'createWithFile' function of CCSkeletonAnimation has wrong number of arguments: %d, was expecting %d\n", argc, 2);
|
||||
|
||||
#if COCOS2D_DEBUG >= 1
|
||||
tolua_lerror:
|
||||
tolua_error(L,"#ferror in function 'createWithFile'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
||||
int tolua_Cocos2d_CCSkeletonAnimation_registerScriptHandler00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!toluafix_isfunction(tolua_S,2,"LUA_FUNCTION",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
int handler = ( toluafix_ref_function(tolua_S,2,0));
|
||||
ScriptHandlerMgr::HandlerType handlerType = static_cast<ScriptHandlerMgr::HandlerType>(SCRIPT_SPINE_EVENT);
|
||||
ScriptHandlerMgr::getInstance()->addObjectHandler((void*)self, handler, handlerType);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'registerScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int tolua_Cocos2d_CCSkeletonAnimation_unregisterScriptHandler00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,2,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
ScriptHandlerMgr::HandlerType handlerType = static_cast<ScriptHandlerMgr::HandlerType>(SCRIPT_SPINE_EVENT);
|
||||
|
||||
ScriptHandlerMgr::getInstance()->removeObjectHandler((void*)self, handlerType);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'unregisterScriptHandler'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static int tolua_Cocos2d_CCSkeletonAnimation_setTimeScale00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!tolua_isnumber(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
LUA_NUMBER scale = tolua_tonumber(tolua_S, 2, 1);
|
||||
self->timeScale = scale;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'setTimeScale'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int tolua_Cocos2d_CCSkeletonAnimation_setDebugSlots00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!tolua_isboolean(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
bool debugSlots = tolua_toboolean(tolua_S, 2, 1);
|
||||
self->debugSlots = debugSlots;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'setDebugSlots'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int tolua_Cocos2d_CCSkeletonAnimation_setDebugBones00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!tolua_isboolean(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
bool debugBones = tolua_toboolean(tolua_S, 2, 1);
|
||||
self->debugBones = debugBones;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'setDebugBones'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int tolua_Cocos2d_CCSkeletonAnimation_setPremultipliedAlpha00(lua_State* tolua_S)
|
||||
{
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_Error tolua_err;
|
||||
if (
|
||||
!tolua_isusertype(tolua_S,1,"CCSkeletonAnimation",0,&tolua_err) ||
|
||||
!tolua_isboolean(tolua_S,2,0,&tolua_err) ||
|
||||
!tolua_isnoobj(tolua_S,3,&tolua_err)
|
||||
)
|
||||
goto tolua_lerror;
|
||||
else
|
||||
#endif
|
||||
{
|
||||
LuaSkeletonAnimation* self = (LuaSkeletonAnimation*) tolua_tousertype(tolua_S,1,0);
|
||||
if (NULL != self ) {
|
||||
bool premultipliedAlpha = tolua_toboolean(tolua_S, 2, 1);
|
||||
self->premultipliedAlpha = premultipliedAlpha;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'setPremultipliedAlpha'.",&tolua_err);
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int tolua_spine_SkeletoneAnimation_setBlendFunc(lua_State* tolua_S)
|
||||
{
|
||||
return tolua_cocos2dx_setBlendFunc<CCSkeletonAnimation>(tolua_S,"CCSkeletonAnimation");
|
||||
}
|
||||
|
||||
|
||||
static void extendCCSkeletonAnimation(lua_State* L)
|
||||
{
|
||||
lua_pushstring(L, "CCSkeletonAnimation");
|
||||
lua_rawget(L, LUA_REGISTRYINDEX);
|
||||
if (lua_istable(L,-1))
|
||||
{
|
||||
tolua_function(L, "create", lua_cocos2dx_CCSkeletonAnimation_createWithFile);
|
||||
tolua_function(L, "registerScriptHandler", tolua_Cocos2d_CCSkeletonAnimation_registerScriptHandler00);
|
||||
tolua_function(L, "unregisterScriptHandler", tolua_Cocos2d_CCSkeletonAnimation_unregisterScriptHandler00);
|
||||
tolua_function(L, "setBlendFunc", tolua_spine_SkeletoneAnimation_setBlendFunc);
|
||||
tolua_function(L, "setTimeScale", tolua_Cocos2d_CCSkeletonAnimation_setTimeScale00);
|
||||
tolua_function(L, "setDebugSlots", tolua_Cocos2d_CCSkeletonAnimation_setDebugSlots00);
|
||||
tolua_function(L, "setDebugBones", tolua_Cocos2d_CCSkeletonAnimation_setDebugBones00);
|
||||
tolua_function(L, "setPremultipliedAlpha", tolua_Cocos2d_CCSkeletonAnimation_setPremultipliedAlpha00);
|
||||
}
|
||||
}
|
||||
|
||||
int register_all_cocos2dx_spine_manual(lua_State* L)
|
||||
{
|
||||
if (nullptr == L)
|
||||
return 0;
|
||||
|
||||
extendCCSkeletonAnimation(L);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
#ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_SPINE_MANUAL_H
|
||||
#define COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_SPINE_MANUAL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "tolua++.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "CCObject.h"
|
||||
|
||||
TOLUA_API int register_all_cocos2dx_spine_manual(lua_State* L);
|
||||
|
||||
|
||||
#endif // #ifndef COCOS_SCRIPTING_LUA_BINDINGS_LUA_COCOS2DX_SPINE_MANUAL_H
|
|
@ -0,0 +1,82 @@
|
|||
local SpineTestLayer1 = nil
|
||||
|
||||
|
||||
--------------------------------------------------------------------
|
||||
--
|
||||
-- SpineTestLayer1
|
||||
--
|
||||
--------------------------------------------------------------------
|
||||
|
||||
SpineTestLayer1 = function()
|
||||
local ret = cc.Layer:create()
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local spineboy
|
||||
|
||||
local addSpineBoy = function()
|
||||
spineboy = ccsp.CCSkeletonAnimation:create(s_pPathSpineBoyJson, s_pPathSpineBoyAtlas, 0.8)
|
||||
ret:addChild(spineboy)
|
||||
spineboy:setPosition(cc.p(s.width/2, 20))
|
||||
spineboy:setMix("walk", "jump", 0.2)
|
||||
spineboy:setMix("jump", "walk", 0.4)
|
||||
spineboy:setTimeScale(0.3)
|
||||
spineboy:setDebugBones(true)
|
||||
spineboy:setAnimation(0, 'walk', false)
|
||||
spineboy:addAnimation(0, 'jump', false)
|
||||
spineboy:addAnimation(0, 'walk', true)
|
||||
spineboy:addAnimation(0, 'jump', true, 4)
|
||||
|
||||
spineboy:registerScriptHandler(function(event)
|
||||
if event.type == 'start' then
|
||||
print(string.format("[spine] %d start: %s",
|
||||
event.trackIndex,
|
||||
event.animation))
|
||||
elseif event.type == 'end' then
|
||||
print(string.format("[spine] %d end: %s",
|
||||
event.trackIndex,
|
||||
event.animation))
|
||||
elseif event.type == 'complete' then
|
||||
print(string.format("[spine] %d complete: %s, %d",
|
||||
event.trackIndex,
|
||||
event.animation,
|
||||
event.loopCount))
|
||||
elseif event.type == 'event' then
|
||||
print(string.format("[spine] %d event: %s, %s: %d, %f, %s",
|
||||
event.trackIndex,
|
||||
event.animation,
|
||||
event.eventData.name,
|
||||
event.eventData.intValue,
|
||||
event.eventData.floatValue,
|
||||
event.eventData.stringValue))
|
||||
end
|
||||
end)
|
||||
|
||||
spineboy:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeOut:create(1),
|
||||
cc.FadeIn:create(1),
|
||||
cc.DelayTime:create(5))))
|
||||
|
||||
|
||||
end
|
||||
|
||||
local function onNodeEvent(event)
|
||||
if event == "enter" then
|
||||
cclog("SpineTestLayer1#onEnter")
|
||||
addSpineBoy()
|
||||
elseif event == "enterTransitionFinish" then
|
||||
cclog("SceneTestLayer1#onEnterTransitionDidFinish")
|
||||
end
|
||||
end
|
||||
|
||||
ret:registerScriptHandler(onNodeEvent)
|
||||
return ret
|
||||
end
|
||||
|
||||
|
||||
function SpineTestMain()
|
||||
cclog("SpineTestMain")
|
||||
local scene = cc.Scene:create()
|
||||
local layer = SpineTestLayer1()
|
||||
scene:addChild(layer, 0)
|
||||
scene:addChild(CreateBackMenuItem())
|
||||
return scene
|
||||
end
|
|
@ -42,6 +42,7 @@ require "luaScript/RenderTextureTest/RenderTextureTest"
|
|||
require "luaScript/RotateWorldTest/RotateWorldTest"
|
||||
require "luaScript/SpriteTest/SpriteTest"
|
||||
require "luaScript/SceneTest/SceneTest"
|
||||
require "luaScript/SpineTest/SpineTest"
|
||||
require "luaScript/Texture2dTest/Texture2dTest"
|
||||
require "luaScript/TileMapTest/TileMapTest"
|
||||
require "luaScript/TouchesTest/TouchesTest"
|
||||
|
@ -97,6 +98,7 @@ local _allTests = {
|
|||
{ isSupported = true, name = "RenderTextureTest" , create_func = RenderTextureTestMain },
|
||||
{ isSupported = true, name = "RotateWorldTest" , create_func = RotateWorldTest },
|
||||
{ isSupported = true, name = "SceneTest" , create_func = SceneTestMain },
|
||||
{ isSupported = true, name = "SpineTest" , create_func = SpineTestMain },
|
||||
{ isSupported = false, name = "SchdulerTest" , create_func= SchdulerTestMain },
|
||||
{ isSupported = false, name = "ShaderTest" , create_func= ShaderTestMain },
|
||||
{ isSupported = true, name = "SpriteTest" , create_func = SpriteTest },
|
||||
|
|
|
@ -35,3 +35,7 @@ s_AtlasTest = "Images/atlastest.png"
|
|||
-- tilemaps resource
|
||||
s_TilesPng = "TileMaps/tiles.png"
|
||||
s_LevelMapTga = "TileMaps/levelmap.tga"
|
||||
|
||||
-- spine test resource
|
||||
s_pPathSpineBoyJson = "spine/spineboy.json"
|
||||
s_pPathSpineBoyAtlas = "spine/spineboy.atlas"
|
|
@ -0,0 +1,61 @@
|
|||
[cocos2dx_spine]
|
||||
# the prefix to be added to the generated functions. You might or might not use this in your own
|
||||
# templates
|
||||
prefix = cocos2dx_spine
|
||||
|
||||
# create a target namespace (in javascript, this would create some code like the equiv. to `ns = ns || {}`)
|
||||
# all classes will be embedded in that namespace
|
||||
target_namespace = ccsp
|
||||
|
||||
android_headers = -I%(androidndkdir)s/platforms/android-14/arch-arm/usr/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/libs/armeabi-v7a/include -I%(androidndkdir)s/sources/cxx-stl/gnu-libstdc++/4.7/include
|
||||
android_flags = -D_SIZE_T_DEFINED_
|
||||
|
||||
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
|
||||
clang_flags = -nostdinc -x c++ -std=c++11
|
||||
|
||||
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/2d -I%(cocosdir)s/cocos/base -I%(cocosdir)s/cocos/gui -I%(cocosdir)s/cocos/physics -I%(cocosdir)s/cocos/2d/platform -I%(cocosdir)s/cocos/2d/platform/android -I%(cocosdir)s/cocos/math/kazmath/include -I%(cocosdir)s/extensions -I%(cocosdir)s/external -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s
|
||||
|
||||
cocos_flags = -DANDROID -DCOCOS2D_JAVASCRIPT
|
||||
|
||||
cxxgenerator_headers =
|
||||
|
||||
# extra arguments for clang
|
||||
extra_arguments = %(android_headers)s %(clang_headers)s %(cxxgenerator_headers)s %(cocos_headers)s %(android_flags)s %(clang_flags)s %(cocos_flags)s %(extra_flags)s
|
||||
|
||||
# what headers to parse
|
||||
headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h
|
||||
|
||||
# what classes to produce code for. You can use regular expressions here. When testing the regular
|
||||
# expression, it will be enclosed in "^$", like this: "^Menu*$".
|
||||
classes = CCSkeleton CCSkeletonAnimation
|
||||
|
||||
# what should we skip? in the format ClassName::[function function]
|
||||
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also
|
||||
# regular expressions, they will not be surrounded by "^$". If you want to skip a whole class, just
|
||||
# add a single "*" as functions. See bellow for several examples. A special class name is "*", which
|
||||
# will apply to all class names. This is a convenience wildcard to be able to skip similar named
|
||||
# functions from all classes.
|
||||
|
||||
skip = CCSkeleton::[CCSkeleton ~CCSkeleton findBone findSlot getAttachment setAttachment update draw createWith.*],
|
||||
CCSkeletonAnimation::[addAnimationState setAnimationStateData update createWith.*]
|
||||
|
||||
rename_functions =
|
||||
|
||||
rename_classes =
|
||||
|
||||
# for all class names, should we remove something when registering in the target VM?
|
||||
remove_prefix =
|
||||
|
||||
# classes for which there will be no "parent" lookup
|
||||
classes_have_no_parents =
|
||||
|
||||
# base classes which will be skipped when their sub-classes found them.
|
||||
base_classes_to_skip = Object ProcessBase
|
||||
|
||||
# classes that create no constructor
|
||||
# Set is special and we will use a hand-written constructor
|
||||
abstract_classes = CCSkeleton CCSkeletonAnimation
|
||||
|
||||
# Determining whether to use script object(js object) to control the lifecycle of native(cpp) object or the other way around. Supported values are 'yes' or 'no'.
|
||||
script_control_cpp = no
|
||||
|
|
@ -87,3 +87,6 @@ LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py
|
|||
|
||||
echo "Generating bindings for cocos2dx_studio..."
|
||||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_studio.ini -s cocos2dx_studio -t lua -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/lua-bindings -n lua_cocos2dx_studio_auto
|
||||
|
||||
echo "Generating bindings for cocos2dx_spine..."
|
||||
LD_LIBRARY_PATH=${CLANG_ROOT}/lib $PYTHON_BIN ${CXX_GENERATOR_ROOT}/generator.py ${TO_JS_ROOT}/cocos2dx_spine.ini -s cocos2dx_spine -t lua -o ${COCOS2DX_ROOT}/cocos/scripting/auto-generated/lua-bindings -n lua_cocos2dx_spine_auto
|
||||
|
|
Loading…
Reference in New Issue