Jump to content

Phaser.Loader load remote url


ReachTheFlagGames
 Share

Recommended Posts

Hello,

 

I'm trying to load an image as such: game.load.image('example', 'http://www.w3school.com.cn/i/ct_html5_canvas_image.gif');

 

But I get the error: Phaser.Loader error loading file: example from URL http://www.w3school.com.cn/i/ct_html5_canvas_image.gif

 

Anyone know what could be causing this or have it's possible to load an image from another domain?

 

Thanks!

Link to comment
Share on other sites

Hi, you can do it like so:

        var file = {            type: 'image',            key: 'example',            url: 'http://www.w3school.com.cn/i/ct_html5_canvas_image.gif',            data: null,            error: false,            loaded: false        };        file.data = new Image();        file.data.name = file.key;        file.data.onload = function () {            file.loaded = true;            game.cache.addImage(file.key, file.url, file.data);        };        file.data.onerror = function () {            file.error = true;        };        file.data.crossOrigin = '';        file.data.src = file.url;
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...