bug修复
This commit is contained in:
1 parent
48186a3608
commit
4a7e69337f
4 files changed
+100
-32
No files matched your search
@@ -707,7 +707,7 @@
|
||||
}
|
||||
updateWorld(skeleton);
|
||||
draw();
|
||||
const entry = state.getCurrent(0);
|
||||
const entry = currentTrack();
|
||||
if (entry) {
|
||||
const currentTime = getTrackAnimationTime(entry);
|
||||
if (now >= statusHoldUntil) {
|
||||
@@ -966,10 +966,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。
|
||||
function currentTrack() {
|
||||
if (!state) return null;
|
||||
try {
|
||||
if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null;
|
||||
if (typeof state.getTrack === 'function') return state.getTrack(0) || null;
|
||||
const tracks = state.tracks;
|
||||
return (tracks && tracks[0]) || null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 跳到指定时间点:暂停播放,重置动画到目标时间
|
||||
function seekTo(time) {
|
||||
if (!state || !skeleton) return;
|
||||
const track = state.getCurrent(0);
|
||||
const track = currentTrack();
|
||||
const anim = track ? track.animation : null;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
@@ -1204,7 +1217,7 @@
|
||||
});
|
||||
document.getElementById('loopCheck').addEventListener('change', (e) => {
|
||||
loop = e.target.checked;
|
||||
const cur = state.getCurrent(0);
|
||||
const cur = currentTrack();
|
||||
if (cur) cur.loop = loop;
|
||||
});
|
||||
document.getElementById('speedRange').addEventListener('input', (e) => {
|
||||
@@ -1246,11 +1259,15 @@
|
||||
});
|
||||
const endTimelineSeek = () => {
|
||||
if (!seeking) return;
|
||||
seekTimelineToNearestFrame();
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
try {
|
||||
seekTimelineToNearestFrame();
|
||||
} finally {
|
||||
// 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
}
|
||||
};
|
||||
timeline.addEventListener('pointerup', endTimelineSeek);
|
||||
// 指针移出滑块后松开时也要完成吸附。
|
||||
|
||||
@@ -707,7 +707,7 @@
|
||||
}
|
||||
updateWorld(skeleton);
|
||||
draw();
|
||||
const entry = state.getCurrent(0);
|
||||
const entry = currentTrack();
|
||||
if (entry) {
|
||||
const currentTime = getTrackAnimationTime(entry);
|
||||
if (now >= statusHoldUntil) {
|
||||
@@ -966,10 +966,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。
|
||||
function currentTrack() {
|
||||
if (!state) return null;
|
||||
try {
|
||||
if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null;
|
||||
if (typeof state.getTrack === 'function') return state.getTrack(0) || null;
|
||||
const tracks = state.tracks;
|
||||
return (tracks && tracks[0]) || null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 跳到指定时间点:暂停播放,重置动画到目标时间
|
||||
function seekTo(time) {
|
||||
if (!state || !skeleton) return;
|
||||
const track = state.getCurrent(0);
|
||||
const track = currentTrack();
|
||||
const anim = track ? track.animation : null;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
@@ -1204,7 +1217,7 @@
|
||||
});
|
||||
document.getElementById('loopCheck').addEventListener('change', (e) => {
|
||||
loop = e.target.checked;
|
||||
const cur = state.getCurrent(0);
|
||||
const cur = currentTrack();
|
||||
if (cur) cur.loop = loop;
|
||||
});
|
||||
document.getElementById('speedRange').addEventListener('input', (e) => {
|
||||
@@ -1246,11 +1259,15 @@
|
||||
});
|
||||
const endTimelineSeek = () => {
|
||||
if (!seeking) return;
|
||||
seekTimelineToNearestFrame();
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
try {
|
||||
seekTimelineToNearestFrame();
|
||||
} finally {
|
||||
// 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
}
|
||||
};
|
||||
timeline.addEventListener('pointerup', endTimelineSeek);
|
||||
// 指针移出滑块后松开时也要完成吸附。
|
||||
|
||||
@@ -707,7 +707,7 @@
|
||||
}
|
||||
updateWorld(skeleton);
|
||||
draw();
|
||||
const entry = state.getCurrent(0);
|
||||
const entry = currentTrack();
|
||||
if (entry) {
|
||||
const currentTime = getTrackAnimationTime(entry);
|
||||
if (now >= statusHoldUntil) {
|
||||
@@ -966,10 +966,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Spine 4.3 起 AnimationState.getCurrent() 被改名为 getTrack(),这里统一做版本兼容。
|
||||
function currentTrack() {
|
||||
if (!state) return null;
|
||||
try {
|
||||
if (typeof state.getCurrent === 'function') return state.getCurrent(0) || null;
|
||||
if (typeof state.getTrack === 'function') return state.getTrack(0) || null;
|
||||
const tracks = state.tracks;
|
||||
return (tracks && tracks[0]) || null;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// 跳到指定时间点:暂停播放,重置动画到目标时间
|
||||
function seekTo(time) {
|
||||
if (!state || !skeleton) return;
|
||||
const track = state.getCurrent(0);
|
||||
const track = currentTrack();
|
||||
const anim = track ? track.animation : null;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
@@ -1204,7 +1217,7 @@
|
||||
});
|
||||
document.getElementById('loopCheck').addEventListener('change', (e) => {
|
||||
loop = e.target.checked;
|
||||
const cur = state.getCurrent(0);
|
||||
const cur = currentTrack();
|
||||
if (cur) cur.loop = loop;
|
||||
});
|
||||
document.getElementById('speedRange').addEventListener('input', (e) => {
|
||||
@@ -1246,11 +1259,15 @@
|
||||
});
|
||||
const endTimelineSeek = () => {
|
||||
if (!seeking) return;
|
||||
seekTimelineToNearestFrame();
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
try {
|
||||
seekTimelineToNearestFrame();
|
||||
} finally {
|
||||
// 无论吸附是否抛错都要复位,否则 seeking 会永久卡住导致时间轴不再同步。
|
||||
seeking = false;
|
||||
playing = false;
|
||||
updatePlayButton();
|
||||
timeline.blur();
|
||||
}
|
||||
};
|
||||
timeline.addEventListener('pointerup', endTimelineSeek);
|
||||
// 指针移出滑块后松开时也要完成吸附。
|
||||
|
||||
Reference in new issue
Block a user