Loading assets remotely with load

Loading assets remotely with load
0

#1

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


#2

Please try this code .

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

#3

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?


#4

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


#5

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.