Reputation: 73
I am fetching images from URL, sometimes it fails with the message below.
GET https://the/image/url::ERR_HTTP2_PROTOCOL_ERROR
This is not caused by Phaser ( although I don't know the exact reason. This can be fixed by re-fetching the files. ), but since I am only using Phaser, I want to add a fallback to Phaser's load API when this happens.
Below is the API I use to load an image.
this.load.image('image_key', 'https://the/image/url')
As the document says, we can add xhrSetting to the third parameter such as async.
this.load.image('image_key', 'https://the/image/url'), {async: true}`
However, I need a fallback to handle my fetching problem (reload the page/re-fetch the files when it fails, otherwise the image will be a green box.), is there any way to achieve it?
Upvotes: 3
Views: 252
Reputation: 801
by adding a listener to loaderror
event, you can find which file has failed
function preload ()
{
this.load.on('loaderror', (reqinfo)=>{
console.log(reqinfo);
})
}
you can find more details here
Upvotes: 1