ReachTheFlagGames Posted November 11, 2013 Share Posted November 11, 2013 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 More sharing options...
Hsaka Posted November 11, 2013 Share Posted November 11, 2013 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 More sharing options...
Chris Posted November 11, 2013 Share Posted November 11, 2013 Loading images from a external server to render them in a canvas tag will always be problematic due to sandbox restrictions in the browser.Try downloading the image and load it from a local folder (on your server). Link to comment Share on other sites More sharing options...
rich Posted November 11, 2013 Share Posted November 11, 2013 You can load assets from other domains, but the server must be CORS enabled or the request will cause your game grief. If ALL of the assets are coming from a different domain (like from a CDN or something) then you can just set the baseURL property of the loader. Link to comment Share on other sites More sharing options...
Recommended Posts