Skip to content

Commit 707f47e

Browse files
committed
Merge pull request #1447 from pandamicro/develop
Fix spine animation listener binding issues
2 parents 42f0e0d + a2e424d commit 707f47e

File tree

5 files changed

+60
-30
lines changed

5 files changed

+60
-30
lines changed

frameworks/js-bindings/bindings/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ LOCAL_EXPORT_CFLAGS := -DCOCOS2D_JAVASCRIPT
4545

4646
LOCAL_C_INCLUDES := $(LOCAL_PATH)/manual \
4747
$(LOCAL_PATH)/manual/cocostudio \
48+
$(LOCAL_PATH)/manual/spine \
4849
$(LOCAL_PATH)/auto \
4950
$(LOCAL_PATH)/../cocos2d-x/cocos/2d \
5051
$(LOCAL_PATH)/../cocos2d-x/cocos/base \

frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -593,30 +593,6 @@ class JSSkeletonAnimationWrapper: public JSCallbackWrapper
593593
}
594594
};
595595

596-
static bool jsb_cocos2dx_spine_setAnimationListener(JSContext *cx, uint32_t argc, jsval *vp)
597-
{
598-
JSObject *obj = JS_THIS_OBJECT(cx, vp);
599-
js_proxy_t *proxy = jsb_get_js_proxy(obj);
600-
601-
spine::SkeletonAnimation* node = (spine::SkeletonAnimation *)(proxy ? proxy->ptr : NULL);
602-
JSB_PRECONDITION2( node, cx, false, "Invalid Native Object");
603-
if (argc == 2) {
604-
JSSkeletonAnimationWrapper *tmpCobj = new JSSkeletonAnimationWrapper();
605-
jsval *argv = JS_ARGV(cx, vp);
606-
607-
tmpCobj->setJSCallbackFunc(argv[1]);
608-
tmpCobj->setJSCallbackThis(argv[0]);
609-
610-
//node->setAnimationListener(tmpCobj, animationStateEvent_selector(JSSkeletonAnimationWrapper::animationCallbackFunc));
611-
612-
JS_SET_RVAL(cx, vp, JSVAL_VOID);
613-
614-
return true;
615-
}
616-
JS_ReportError(cx, "Invalid number of arguments");
617-
return false;
618-
}
619-
620596
extern JSObject* jsb_spine_SkeletonRenderer_prototype;
621597
extern JSObject* jsb_spine_SkeletonAnimation_prototype;
622598

@@ -630,5 +606,4 @@ void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global)
630606
JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "getCurrent", jsb_cocos2dx_spine_getCurrent, 1, JSPROP_ENUMERATE | JSPROP_PERMANENT);
631607
JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimation", jsb_cocos2dx_spine_setAnimation, 3, JSPROP_ENUMERATE | JSPROP_PERMANENT);
632608
JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "addAnimation", jsb_cocos2dx_spine_addAnimation, 4, JSPROP_ENUMERATE | JSPROP_PERMANENT);
633-
JS_DefineFunction(cx, jsb_spine_SkeletonAnimation_prototype, "setAnimationListener", jsb_cocos2dx_spine_setAnimationListener, 2, JSPROP_ENUMERATE | JSPROP_PERMANENT);
634609
}

frameworks/js-bindings/bindings/manual/spine/jsb_cocos2dx_spine_manual.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,23 @@
2525
#define __jsb_cocos2dx_spine_manual__
2626

2727

28-
#include "jsapi.h"
29-
#include "jsfriendapi.h"
28+
#include "js/Value.h"
29+
#include "js/TypeDecls.h"
30+
#include "spine/spine-cocos2dx.h"
3031

3132
void register_all_cocos2dx_spine_manual(JSContext* cx, JSObject* global);
3233

34+
extern jsval speventdata_to_jsval(JSContext* cx, spEventData& v);
35+
extern jsval spevent_to_jsval(JSContext* cx, spEvent& v);
36+
extern jsval spbonedata_to_jsval(JSContext* cx, const spBoneData* v);
37+
extern jsval spbone_to_jsval(JSContext* cx, spBone& v);
38+
extern jsval spskeleton_to_jsval(JSContext* cx, spSkeleton& v);
39+
extern jsval spattachment_to_jsval(JSContext* cx, spAttachment& v);
40+
extern jsval spslotdata_to_jsval(JSContext* cx, spSlotData& v);
41+
extern jsval spslot_to_jsval(JSContext* cx, spSlot& v);
42+
extern jsval sptimeline_to_jsval(JSContext* cx, spTimeline& v);
43+
extern jsval spanimationstate_to_jsval(JSContext* cx, spAnimationState& v);
44+
extern jsval spanimation_to_jsval(JSContext* cx, spAnimation& v);
45+
extern jsval sptrackentry_to_jsval(JSContext* cx, spTrackEntry& v);
46+
3347
#endif /* defined(__jsb_cocos2dx_spine_manual__) */

frameworks/js-bindings/bindings/script/jsb_spine.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
* THE SOFTWARE.
2121
*/
2222

23+
sp.ANIMATION_EVENT_TYPE = {
24+
START: 0,
25+
END: 1,
26+
COMPLETE: 2,
27+
EVENT: 3
28+
};
29+
2330
sp.SkeletonAnimation.prototype._ctor = function(skeletonDataFile, atlasFile, scale) {
2431
if(atlasFile) {
2532
if (isNaN(scale)) {
@@ -28,7 +35,40 @@ sp.SkeletonAnimation.prototype._ctor = function(skeletonDataFile, atlasFile, sca
2835

2936
this.initWithFile(skeletonDataFile, atlasFile, scale);
3037
this.initialize();
38+
39+
this._target = null;
40+
this._callback = null;
3141
}
3242
};
3343

3444
sp.SkeletonAnimation.extend = cc.Class.extend;
45+
46+
// Temporary solution before upgrade the Spine API
47+
sp.SkeletonAnimation.prototype.setAnimationListener = function (target, callback) {
48+
this._target = target;
49+
this._callback = callback;
50+
51+
this.setStartListener(function (trackIndex) {
52+
if (this._target && this._callback) {
53+
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.START, null, 0);
54+
}
55+
});
56+
57+
this.setEndListener(function (trackIndex) {
58+
if (this._target && this._callback) {
59+
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.END, null, 0);
60+
}
61+
});
62+
63+
this.setCompleteListener(function (trackIndex, loopCount) {
64+
if (this._target && this._callback) {
65+
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.COMPLETE, null, loopCount);
66+
}
67+
});
68+
69+
this.setEventListener(function (trackIndex, event) {
70+
if (this._target && this._callback) {
71+
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.EVENT, event, 0);
72+
}
73+
});
74+
}

tools/tojs/cocos2dx_spine.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android_flags = -D_SIZE_T_DEFINED_
99
clang_headers = -I%(clangllvmdir)s/lib/clang/3.3/include
1010
clang_flags = -nostdinc -x c++ -std=c++11 -U __SSE__
1111

12-
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android
12+
cocos_headers = -I%(cocosdir)s/cocos -I%(cocosdir)s/cocos/editor-support -I%(cocosdir)s/cocos/platform/android -I%(jsbdir)s/external/spidermonkey/include/android
1313

1414
cocos_flags = -DANDROID
1515

@@ -18,14 +18,14 @@ cxxgenerator_headers =
1818
# extra arguments for clang
1919
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
2020

21-
headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h
21+
headers = %(cocosdir)s/cocos/editor-support/spine/spine-cocos2dx.h %(jsbdir)s/bindings/manual/spine/jsb_cocos2dx_spine_manual.h
2222

2323
classes = SkeletonRenderer SkeletonAnimation
2424

2525
classes_need_extend = SkeletonAnimation
2626

2727
skip = SkeletonRenderer::[createWithData findBone findSlot getAttachment],
28-
SkeletonAnimation::[createWithData getCurrent setAnimation addAnimation setAnimationListener]
28+
SkeletonAnimation::[createWithData getCurrent setAnimation addAnimation]
2929

3030
remove_prefix =
3131

0 commit comments

Comments
 (0)