How to load images directly from jsb.fileUtils.getWritablePath?

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

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 :slight_smile:

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;
});

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.