Skip to content

Commit f8974f4

Browse files
committed
playClip works better when timer fires slowly
1 parent 925a3dd commit f8974f4

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/stackTools/playClip.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function playClip(element, framesPerSecond) {
139139
playClipData = {
140140
intervalId: undefined,
141141
framesPerSecond: 30,
142-
lastFrameTimeStamp: undefined,
142+
lastFrameTimeStamp: new Date().getTime(),
143143
frameRate: 0,
144144
frameTimeVector: undefined,
145145
ignoreFrameTimeVector: false,
@@ -182,15 +182,23 @@ function playClip(element, framesPerSecond) {
182182
startLoadingHandler,
183183
endLoadingHandler,
184184
errorLoadingHandler,
185+
newlastFrameTimeStamp = new Date().getTime(),
186+
deltatime = newlastFrameTimeStamp - playClipData.lastFrameTimeStamp,
187+
frames = Math.round((playClipData.framesPerSecond / 1000) * deltatime),
185188
newImageIdIndex = stackData.currentImageIdIndex;
186189

187190
const imageCount = stackData.imageIds.length;
188191

192+
if (frames > 1) {
193+
console.log('frames:', frames);
194+
}
195+
189196
if (playClipData.reverse) {
190-
newImageIdIndex--;
197+
newImageIdIndex -= frames;
191198
} else {
192-
newImageIdIndex++;
199+
newImageIdIndex += frames;
193200
}
201+
playClipData.lastFrameTimeStamp = newlastFrameTimeStamp;
194202

195203
if (
196204
!playClipData.loop &&

0 commit comments

Comments
 (0)