Skip to content

Commit 92e7b92

Browse files
author
SeanLin
committed
Merge pull request #313 from ucchen/master
add setAnimationListener test
2 parents bd10344 + 6bd64f9 commit 92e7b92

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

tests/SpineTest/SpineTest.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626

2727
var sp = sp || {};
2828

29+
var ANIMATION_TYPE = {
30+
ANIMATION_START: 0,
31+
ANIMATION_END: 1,
32+
ANIMATION_COMPLETE: 2,
33+
ANIMATION_EVENT: 3
34+
};
35+
2936
SpineTestScene = TestScene.extend({
3037

3138
runThisTest:function () {
@@ -53,6 +60,7 @@ SpineTest = BaseTestLayer.extend({
5360
spineboy.setAnimation(0, 'walk', true);
5461
spineboy.setMix('walk', 'jump', 0.2);
5562
spineboy.setMix('jump', 'walk', 0.4);
63+
spineboy.setAnimationListener(this, this.animationStateEvent);
5664
this.addChild(spineboy, 4);
5765
},
5866
onBackCallback:function (sender) {
@@ -70,6 +78,29 @@ SpineTest = BaseTestLayer.extend({
7078
return "Spine test";
7179
},
7280

81+
animationStateEvent: function(obj, trackIndex, type, event, loopCount) {
82+
var entry = spineboy.getCurrent();
83+
var animationName = (entry && entry.animation) ? entry.animation.name : 0;
84+
85+
switch(type)
86+
{
87+
case ANIMATION_TYPE.ANIMATION_START:
88+
cc.log(trackIndex + " start: " + animationName);
89+
break;
90+
case ANIMATION_TYPE.ANIMATION_END:
91+
cc.log(trackIndex + " end:" + animationName);
92+
break;
93+
case ANIMATION_TYPE.ANIMATION_EVENT:
94+
cc.log(trackIndex + " event: " + animationName);
95+
break;
96+
case ANIMATION_TYPE.ANIMATION_COMPLETE:
97+
cc.log(trackIndex + " complete: " + animationName + "," + loopCount);
98+
break;
99+
default :
100+
break;
101+
}
102+
},
103+
73104
// automation
74105
numberOfPendingTests:function() {
75106
return 1;
@@ -82,4 +113,4 @@ SpineTest = BaseTestLayer.extend({
82113

83114
SpineTest.create = function () {
84115
return new SpineTest();
85-
};
116+
};

0 commit comments

Comments
 (0)