New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preload Sprite Lab background images #29358
Conversation
return new Promise(resolve => { | ||
backgrounds.forEach(background => { | ||
this.p5.loadImage(background.sourceUrl, image => { | ||
this.p5._predefinedBackgrounds[background.legacyParam] = image; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this still work if there is no legacyParam? i.e. if we add more background images
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, worth adding a test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we add more background images, then we will need additional logic to key by name in those cases. I think it's fine to hold off on adding that until we actually add new images, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
let backgroundImage = this.loadImage(img); | ||
backgroundImage.name = img; | ||
spriteUtils.background = backgroundImage; | ||
if (this._predefinedBackgrounds[img]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two questions:
- Should there be an else here?
- Do we use loadImage anywhere anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- No, I think we decided yesterday not to try to live-load the image if we don't have it preloaded. That case should never come up, so it would basically just be untested/unused code. The image parameter can only be set by the values in the dropdown, so as long as we have all of those images preloaded, we will never reach an else case.
loadImage
is only called during the preload stage now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This change preloads the background images in the dropdown for the
setBackgroundImage
block in the preload phase of the P5 lifecycle. This change is necessary to show the background images in preview mode.Old:
New:
Currently, the
name
field inbackgrounds.json
is unused, since thesetBackgroundImage
block uses explicit URLs (thelegacyParam
field inbackgrounds.json
). Ideally, over the longterm, we can make a plan to migrate the block XML for that block, and then use thename
field instead oflegacyParam