cocos3D 加载微信头像的方法分享

 loadHeadIcon: function (headSprite:SpriteComponent, url:string, width:number) {
    if (url == '' || url == null) return;
    url = 'https://ss1.baidu.com/6ONXsjip0QIZ8tyhnq/it/u=1948968049,2186058924&fm=173&app=49&f=JPEG?w=526&h=449&s=D68225E157279F5942D174250300E0C4';
    cc.loader.load({ url: url, type: 'png' }, function (err, image:ImageAsset) {
      if (err) {
        return cc.log(err);
      }

      if (cc.isValid(headSprite.node)) {
        let frame = new SpriteFrame();
        frame.texture = image._texture;
        headSprite.spriteFrame = frame;
        headSprite.node.width = width;
        headSprite.node.height = width;
      }
    });
  },

注意这个函数里我为了做测试就把url写死了,大家记得删除掉这一行哈

2赞