I would like to load images from the Internet and display them after this.load.once()
It was still not working…
Can anyone help to see what is wrong ??
create() {
// Dynamically load an image from the internet
const imageUrl = 'https://example.com/your-image.png';
this.loadImageFromUrl('bomb', imageUrl);
}
loadImageFromUrl(key, url) {
// Load the image with a specific key from the provided URL
this.load.image(key, url);
// Set up the event listener for when the image is loaded
this.load.once('filecomplete-image-' + key, this.imageLoaded, this);
// Optionally, handle any load errors
this.load.on('loaderror', this.loadError, this);
// Start the loading process
this.load.start();
}
imageLoaded(key) {
console.log(`Image ${key} loaded successfully!`);
// Use the loaded image (e.g., add it to the scene)
this.add.image(400, 300, key);
}
loadError(file) {
console.error(`Error loading ${file.src}`);
}