Hello,
I am using Creator 3.4.2
I used Downloader
for downloading images from server and stored into getWritablePath
which is working fine.
But next i want to display sprite/node based on those downloaded images from getWritablePath.
How can i do that? I tried below code but its not working.
var dirpath = jsb.fileUtils.getWritablePath() + 'img/';
var filepath = dirpath + 'test1.png';
if(jsb.fileUtils.isFileExist(filepath))
log("Yes, file exist");
resources.load(filepath, SpriteFrame, (error: Error, asset: SpriteFrame) => {
log("onSpriteLoad called " + error);
this.logoSp.spriteFrame = asset;
});
Regards,
Smit
linrm
April 27, 2022, 11:04am
#2
you can use cc.loader.load like the demo you mentioned :
I also tried this but its giving error in 3.4.2
new SpriteFrame(res);
SpriteFrame takes 0 arguments.
Got magic code from documentation
https://docs.cocos.com/creator/manual/en/asset/dynamic-load-resources.html?h=absolute%20path
And its working perfectly fine
var dirpath = jsb.fileUtils.getWritablePath() + 'img/';
var filepath = dirpath + 'test1.png';
assetManager.loadRemote<ImageAsset>(filepath, function (err, imageAsset) {
const spriteFrame = new SpriteFrame();
const texture = new Texture2D();
texture.image = imageAsset;
spriteFrame.texture = texture;
// ...
_logo.getComponent(Sprite).spriteFrame = spriteFrame;
});
system
closed
April 29, 2022, 2:24am
#5
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.