加载微信头像

有没有大佬可以提供一个creator3D 加载微信头像的方法

已解决

怎么解决的啊,大佬给个方案呢

大佬能给个方案吗,加载不出来…

你等等,我给你瞅瞅

好的,非常感谢!!

你是微信排行榜的头像吧

类似这种没有后缀的头像地址,
https://thirdwx.qlogo.cn/mmopen/vi_32/XA9Dx0Gv5dT0Cqic3Ghmt7ftVU8VhicGQiaTZdMS63ojMy7yF5PmXta7DGicW0Uge53TbiakdrNdaiaTiarTaGQH4JY7Q/132

我用的官方给的代码,直接报错 :rofl:

debug.ts:103

   Can not parse this input:{"preset":"remote","maxRetryCount":4} Error: Can not parse this input:{"preset":"remote","maxRetryCount":4}
at _loop (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:143341:15)
at parse (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:143346:18)
at Pipeline.sync (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:141948:26)
at preprocess (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:142267:53)
at Pipeline._flow (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:142003:11)
at http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:142015:23
at http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:140939:7
at cb (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:143679:11)
at Task.onComplete (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:140924:11)
at Task.dispatch (http://localhost:7456/scripting/engine/bin/.cache/dev/preview/bundled/index.js:143081:22)

createImage(touxiang,avatarUrl) {
let wx = window[“wx”];
if (CC_WECHATGAME) {
try {
let image = wx.createImage();
image.onload = () => {
try {
let texture = new cc.Texture2D();
texture.initWithElement(image);
texture.handleLoadedTexture();
touxiang.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
} catch (e) {
touxiang.active = false;
}
};
image.src = avatarUrl;
} catch (e) {
console.log(e);
touxiang.active = false;
}
} else {
cc.loader.load({
url: avatarUrl, type: ‘jpg’
}, (err, texture) => {
touxiang.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
});
}
}

1赞

你试试这个

官方代码地址:
https://docs.cocos.com/creator/manual/zh/asset/dynamic-load-resources.html

好嘞,感谢!!我试试

这是之前老早的代码了,我也不知道能不能用,

好像不太行,这是2.x的代码了 :rofl:

嗯嗯,可以试着改一下

你的代码格式化下好点

:rofl::rofl::rofl: 草率了