-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix skeleton's setTrackXXXListener doesn't work on web platform #16512
Conversation
(cherry picked from commit 9b90131d968185bd3d73c30f1a11960a9786fbde)
instance->onAnimationStateEvent(entry, type, event); | ||
} | ||
|
||
void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the function static
.
void trackEntryCallback(AnimationState *state, EventType type, TrackEntry *entry, Event *event) { | ||
(static_cast<SpineSkeletonInstance *>(state->getRendererObject()))->onTrackEntryEvent(entry, type, event); | ||
if (type == EventType_Dispose) { | ||
if (entry->getRendererObject()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the renderobject be nullptr? If so, the above line
(static_cast<SpineSkeletonInstance *>(state->getRendererObject()))->onTrackEntryEvent(entry, type, event);
should also consider the situation of nullptr
.
_trackListenerID = trackId; | ||
entry->setRendererObject(this); | ||
entry->setListener(trackEntryCallback); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we output an error if render object is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
render object only used to prevent setTrackListener multi times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So setTrackListener could not be invoked multiple times for the same trackId?
If I want to replace entry for the same trackId, how to achieve that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trackId is generated by engine internal, one trackEntry only has one trackListener. While dispose_event called, trackEntry's listener will be reset to null.
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -51741,8 +51741,9 @@
dtRate: number;
isCache: boolean;
isDelete: boolean;
enable: boolean;
+ setTrackEntryListener: any;
initSkeleton(data: SkeletonData);
getAnimationState();
setAnimation(trackIndex: number, name: string, loop: boolean): spine.TrackEntry | null;
setSkin(name: string);
@@ -67139,10 +67140,11 @@
end?: ((entry: sp.spine.TrackEntry) => void);
dispose?: ((entry: sp.spine.TrackEntry) => void);
complete?: ((entry: sp.spine.TrackEntry) => void);
event?: ((entry: sp.spine.TrackEntry, event: sp.spine.Event) => void);
- static getListeners(entry: sp.spine.TrackEntry): sp.spine.AnimationStateListener;
+ static getListeners(entry: sp.spine.TrackEntry, instance: sp.spine.SkeletonInstance): sp.spine.AnimationStateListener;
static emitListener(id: number, entry: sp.spine.TrackEntry, event: sp.spine.Event): void;
+ static emitTrackEntryListener(id: number, entry: sp.spine.TrackEntry, event: sp.spine.Event, eventType: sp.spine.EventType): void;
static addListener(listener: _cocos_spine_track_entry_listeners__CommonTrackEntryListener): number;
}
export class _cocos_spine_skeleton_cache__SpineDrawItem {
iCount: number;
|
native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h
Outdated
Show resolved
Hide resolved
native/cocos/editor-support/spine-wasm/spine-skeleton-instance.h
Outdated
Show resolved
Hide resolved
curTrack.listener.event(entry, event); | ||
} | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to handle default case and print an error/warning log.
Re: # #16493
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: