Skip to content

Commit aa8d9a5

Browse files
committed
fixed the bug of black-frames
1 parent f76b2b6 commit aa8d9a5

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/image/loading_displaying.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ function loadingDisplaying(p5, fn){
256256
units: 'seconds',
257257
silent: false,
258258
notificationDuration: 0,
259-
notificationID: 'progressBar'
259+
notificationID: 'progressBar',
260+
reset:true
260261
}
261262
) {
262263
// validate parameters
@@ -273,7 +274,7 @@ function loadingDisplaying(p5, fn){
273274
const silent = (options && options.silent) || false;
274275
const notificationDuration = (options && options.notificationDuration) || 0;
275276
const notificationID = (options && options.notificationID) || 'progressBar';
276-
277+
const resetAnimation = (options && options.reset !== undefined) ? options.reset : true;
277278
// if arguments in the options object are not correct, cancel operation
278279
if (typeof delay !== 'number') {
279280
throw TypeError('Delay parameter must be a number');
@@ -324,11 +325,19 @@ function loadingDisplaying(p5, fn){
324325
// that duration translates to
325326
const nFrames = units === 'seconds' ? duration * _frameRate : duration;
326327
const nFramesDelay = units === 'seconds' ? delay * _frameRate : delay;
327-
const totalNumberOfFrames = nFrames + nFramesDelay;
328328

329329
// initialize variables for the frames processing
330-
let frameIterator = nFramesDelay;
331-
this.frameCount = frameIterator;
330+
let frameIterator;
331+
let totalNumberOfFrames;
332+
if (resetAnimation) {
333+
frameIterator = nFramesDelay;
334+
this.frameCount = frameIterator;
335+
totalNumberOfFrames = nFrames + nFramesDelay;
336+
} else {
337+
frameIterator = this.frameCount + nFramesDelay;
338+
totalNumberOfFrames = frameIterator + nFrames;
339+
}
340+
332341

333342
const lastPixelDensity = this._renderer._pixelDensity;
334343
this.pixelDensity(1);
@@ -381,7 +390,7 @@ function loadingDisplaying(p5, fn){
381390
to be drawn and immediately save it to a buffer and continue
382391
*/
383392
this.redraw();
384-
393+
await new Promise(resolve => requestAnimationFrame(resolve));
385394
// depending on the context we'll extract the pixels one way
386395
// or another
387396
let data = undefined;

0 commit comments

Comments
 (0)