diff --git a/README.md b/README.md index 267a9d7..4de83b4 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Add-on based on **Mikal's** sample from this thread: [https://www.construct.net/en/forum/construct-3/general-discussion-7/spine-animation-js-template-145940 ](https://www.construct.net/en/forum/construct-3/general-discussion-7/spine-animation-js-template-145940) ## Downloads -[Add-on](https://github.com/gritsenko/c3_spine_plugin/releases/download/1.16.1/Spine-v1.16.1.c3addon) +[Add-on](https://github.com/gritsenko/c3_spine_plugin/releases/download/1.16.2/Spine-v1.16.2.c3addon) [Previous Add-on Versions](https://github.com/gritsenko/c3_spine_plugin/tree/master/dist) @@ -84,6 +84,7 @@ Useful for Dragon Bones Spine JSON export and earlier Spine versions. ## Wishlist - Preview Spine render in editor (dependent on C3 editor SDK updates) ## Release notes +- 1.16.2 Change behavior of *Set Animation w/ starting time* to not trigger events if the events were before the starting time. - 1.16.1 Bug fix for slot color (handle reset and new skin properly, only apply dark color if Tint Black is set in Spine project for slot). - 1.16.0 Add Set slot dark color, Apply Slot color, Reset Slot color. Add Set animation time and starting point of Set animation (beginning, current time, current ratio). Deprecated set color attachment (did not support dark color). - 1.15.2 Add project sampling support to Spine C3 texture. diff --git a/dist/Spine-v1.16.2.c3addon b/dist/Spine-v1.16.2.c3addon new file mode 100644 index 0000000..07c768e Binary files /dev/null and b/dist/Spine-v1.16.2.c3addon differ diff --git a/src/addon.json b/src/addon.json index a9d5961..b491c64 100755 --- a/src/addon.json +++ b/src/addon.json @@ -3,7 +3,7 @@ "type": "plugin", "name": "Spine", "id": "Gritsenko_Spine", - "version": "1.16.1", + "version": "1.16.2", "author": "Mikal and Igor Gritsenko", "website": "https://gritsenko.github.io/c3_spine_plugin", "documentation": "https://gritsenko.github.io/c3_spine_plugin", diff --git a/src/c3runtime/instance.js b/src/c3runtime/instance.js index 206bbd9..a124b83 100644 --- a/src/c3runtime/instance.js +++ b/src/c3runtime/instance.js @@ -281,6 +281,10 @@ } updateCurrentAnimation(loop,start) { + + if (!this.skeletonInfo) return; + if (!this.skeletonInfo.skeleton) return; + try { const state = this.skeletonInfo.state; const skeleton = this.skeletonInfo.skeleton; @@ -291,23 +295,14 @@ if (track) { // calculate ratio and time currentTime = track.trackTime; - currentRatio = (track.animationLast+track.trackTime-track.trackLast)/(track.animationEnd-track.animationStart); - console.log('[Spine] currentTime', currentTime, currentRatio); + if (track.animationEnd != track.animationStart && track.animationEnd > track.animationStart) + { + currentRatio = (track.animationLast+track.trackTime-track.trackLast)/(track.animationEnd-track.animationStart); + } + // console.log('[Spine] currentTime', currentTime, currentRatio); } state.setAnimation(0, this.animationName, loop); - - state.tracks[0].listener = { - complete: (trackEntry, count) => { - this.completeAnimationName = this.animationName; - this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnimationFinished); - this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnyAnimationFinished); - }, - event: (trackIndex, event) => { - this.completeEventName = event.data.name; - this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnEvent); - } - }; switch (start) { @@ -317,16 +312,37 @@ default: break; } - state.apply(skeleton); - - - - console.log('[Spine] trackTime 0', state.tracks[0].trackTime); - - console.log('[Spine] trackTime 1', state.tracks[0].trackTime); - - console.log('[Spine] track:', state.tracks[0]); - + if (start == 0 || (start == 2 && currentRatio == 0)) + // If starting from beginning or 0 ratio add listners so they'll trigger at 0 + { + state.tracks[0].listener = { + complete: (trackEntry, count) => { + this.completeAnimationName = this.animationName; + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnimationFinished); + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnyAnimationFinished); + }, + event: (trackIndex, event) => { + this.completeEventName = event.data.name; + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnEvent); + } + }; + state.apply(skeleton); + } else + // If starting later, apply time, then enable listeners so they do not trigger on past events + { + state.apply(skeleton); + state.tracks[0].listener = { + complete: (trackEntry, count) => { + this.completeAnimationName = this.animationName; + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnimationFinished); + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnAnyAnimationFinished); + }, + event: (trackIndex, event) => { + this.completeEventName = event.data.name; + this.Trigger(C3.Plugins.Gritsenko_Spine.Cnds.OnEvent); + } + }; + } } catch (ex) { console.error(ex); alert(ex + "\n\n available animations: \n" + this.animationNames.join("\n")); diff --git a/src/plugin.js b/src/plugin.js index c8957a1..a75c27b 100755 --- a/src/plugin.js +++ b/src/plugin.js @@ -2,7 +2,7 @@ { const PLUGIN_ID = "Gritsenko_Spine"; - const PLUGIN_VERSION = "1.16.1"; + const PLUGIN_VERSION = "1.16.2"; const PLUGIN_CATEGORY = "general"; const PLUGIN_CLASS = SDK.Plugins.Gritsenko_Spine = class SpinePlugin extends SDK.IPluginBase {