Loading assets remotely with load

Loading assets remotely with load


Hi there,

So I am trying to load a png from a server using cc.loader.load(url, progressCB, completionCB), the url’s ending point is /filename.png.
For some reason, the texture parameter of the completionCallback function is null, and I am not sure why.
When I am opening the url in a browser, I can see the picture, but for some reason it won’t load.

I am using Cocos Creator v1.10.2
spriteNode is a Node with a Sprite component on it.
You can see my code below.

cc.loader.load(msg, () => {cc.log("ProgressCB")}, (err, texture) => 
    cc.log(texture);    //null
    this.spriteNode.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);

I hope someone can help me with that.

Best regards


Please try this code .

var remoteUrl = "http://www.mywebsite.com/res/background/background.png";
  cc.loader.load({url: remoteUrl, type: 'png'},(err , texture) => {
          cc.error("Error : "+ (err.message || err));
          // use texture directly ... 
          var s_frame = this.spriteNode.getComponent(cc.Sprite).spriteFrame;


Thank you for your reply,

Now I am getting:

[ERROR]: Error : Load image failed: https://www.mywebsite.com/characters/images/charname.png

Do you know what could cause this?
Is it maybe because it is an https? Or does it have to be somewhere in /res/ on the server as well?


Can you please double check the url. because it works fine in my project.


The url is fine. I can copy it out of the error log and open it in the browser, then I see the picture.
But somehow Cocos can’t load it.