Fix for gif not animating when drawing to p5.graphics #6935
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #6925
Changes:
From:
const curTime = pInst._lastRealFrameTime
To:
const curTime = pInst._lastRealFrameTime || window.performance.now();
In /image/p5.Image.js under the _animateGif(pInst) helper function
_lastRealFrameTime in main.js is set to window.performance.now() which starts the browser timer, however like the issue poster mentioned pInst._lastRealFrameTime exists on the main canvas but not graphics if you attach a gif to a graphic like below then only the first frame of the gif will animate since the helper function sets curTime to pInst._lastRealFrameTime.
`let cnv;
function preload() {
gif = loadImage('test.gif)
}
function setup() {
createCanvas(100, 100);
cnv = createGraphics(100, 100);
}
function draw() {
cnv.background(255);
cnv.image(gif, 0, 0);
image(cnv, 0, 0);
}`
In /image/p5.Image.js then under the _animateGif(pInst)
curTime
which is set topInst._lastRealFrameTime
will not exist (undefined) thus adding|| window.performance.now();
will start the timer again allowing the gif to animate beyond the first frame.Screenshots of the change:
PR Checklist
npm run lint
passes