微信的头像地址是没有后缀的,比如这样:
https://thirdwx.qlogo.cn/mmopen/vi_32/XA9Dx0Gv5dT0Cqic3Ghmt7ftVU8VhicGQiaTZdMS63ojMy7yF5PmXta7DGicW0Uge53TbiakdrNdaiaTiarTaGQH4JY7Q/132
文档示例:
https://docs.cocos.com/creator/manual/zh/asset/dynamic-load-resources.html
按照文档的示例写了如下测试代码:
setMyAvatar(){
var assetManager = new AssetManager()
var remoteUrl = 'https://thirdwx.qlogo.cn/mmopen/vi_32/XA9Dx0Gv5dT0Cqic3Ghmt7ftVU8VhicGQiaTZdMS63ojMy7yF5PmXta7DGicW0Uge53TbiakdrNdaiaTiarTaGQH4JY7Q/132'
assetManager.loadRemote<ImageAsset>(remoteUrl, {ext: '.jpg'}, function (err, imageAsset) {
const spriteFrame = new SpriteFrame();
const texture = new Texture2D();
texture.image = imageAsset;
spriteFrame.texture = texture;
});
}
然后在模拟器中的报错如下:
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)
