Modify the callback argument of spine event listener.

Change the argument trackIndex to trackEntry.
This commit is contained in:
zhangbin
2017-02-10 17:16:25 +08:00
parent c47785c392
commit d27bfa164e
2 changed files with 28 additions and 35 deletions
@@ -22,38 +22,19 @@
sp.ANIMATION_EVENT_TYPE = {
START: 0,
END: 1,
COMPLETE: 2,
EVENT: 3
INTERRUPT: 1,
END: 2,
DISPOSE: 3,
COMPLETE: 4,
EVENT: 5
};
// The methods are added to be compatibility with old versions.
sp.SkeletonAnimation.prototype.setStartListener = function (listener) {
this._startListener = listener;
this.setStartListenerNative(function (trackEntry) {
this._startListener(trackEntry.trackIndex);
});
};
sp.SkeletonAnimation.prototype.setEndListener = function (listener) {
this._endListener = listener;
this.setEndListenerNative(function (trackEntry) {
this._endListener(trackEntry.trackIndex);
});
};
sp.SkeletonAnimation.prototype.setCompleteListener = function (listener) {
this._compeleteListener = listener;
this.setCompleteListenerNative(function (trackEntry) {
var loopCount = Math.floor(trackEntry.trackTime / trackEntry.animationEnd);
this._compeleteListener(trackEntry.trackIndex, loopCount);
});
};
sp.SkeletonAnimation.prototype.setEventListener = function (listener) {
this._eventListener = listener;
this.setEventListenerNative(function (trackEntry, event) {
this._eventListener(trackEntry.trackIndex, event);
this._compeleteListener(trackEntry, loopCount);
});
};
@@ -62,27 +43,39 @@ sp.SkeletonAnimation.prototype.setAnimationListener = function (target, callback
this._target = target;
this._callback = callback;
this.setStartListener(function (trackIndex) {
this.setStartListener(function (trackEntry) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.START, null, 0);
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.START, null, 0);
}
});
this.setEndListener(function (trackIndex) {
this.setInterruptListener(function (trackEntry) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.END, null, 0);
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.INTERRUPT, null, 0);
}
});
this.setCompleteListener(function (trackIndex, loopCount) {
this.setEndListener(function (trackEntry) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.COMPLETE, null, loopCount);
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.END, null, 0);
}
});
this.setEventListener(function (trackIndex, event) {
this.setDisposeListener(function (trackEntry) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackIndex, sp.ANIMATION_EVENT_TYPE.EVENT, event, 0);
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.DISPOSE, null, 0);
}
});
this.setCompleteListener(function (trackEntry, loopCount) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.COMPLETE, null, loopCount);
}
});
this.setEventListener(function (trackEntry, event) {
if (this._target && this._callback) {
this._callback.call(this._target, this, trackEntry, sp.ANIMATION_EVENT_TYPE.EVENT, event, 0);
}
});
}
+2 -2
View File
@@ -27,7 +27,7 @@ classes = SkeletonRenderer SkeletonAnimation
classes_need_extend = SkeletonAnimation
skip = SkeletonRenderer::[createWithData findBone findSlot getAttachment initWithData],
SkeletonAnimation::[createWithData getCurrent setAnimation addAnimation onTrackEntryEvent setTrackStartListener setTrackEndListener onAnimationStateEvent setTrackCompleteListener]
SkeletonAnimation::[createWithData getCurrent setAnimation addAnimation onTrackEntryEvent onAnimationStateEvent setTrackStartListener setTrackEndListener setTrackInterruptListener setTrackDisposeListener setTrackCompleteListener setTrackEventListener]
remove_prefix =
@@ -39,7 +39,7 @@ abstract_classes =
script_control_cpp =
rename_functions = SkeletonAnimation::[createWithFile=create setStartListener=setStartListenerNative setEndListener=setEndListenerNative setCompleteListener=setCompleteListenerNative setEventListener=setEventListenerNative],
rename_functions = SkeletonAnimation::[createWithFile=create setCompleteListener=setCompleteListenerNative setTrackCompleteListener=setTrackCompleteListenerNative],
SkeletonRenderer::[createWithFile=create]
rename_classes = SkeletonRenderer::Skeleton