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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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