Tuesday, November 22, 2022
HomeGame DevelopmentHow you can create Sprite Node with Picture from URL in Cocos...

How you can create Sprite Node with Picture from URL in Cocos Creator V3? – Cocos Creator


I need to create new Sprite Node with picture load from distant URL, however It doesn’t work.
That is my code:

// distant load photograph
assetManager.loadRemote<ImageAsset>(photo_url, (err, imageAsset) => {
    const spriteFrame = SpriteFrame.createWithImage(imageAsset);

    const newNode = new Node()

    // add new Sprite element
    newNode.addComponent(Sprite)
    const sprite = newNode.getComponent(Sprite)

    // assign sprite body to the brand new Sprite Node
    sprite.spriteFrame = spriteFrame

    // set node content material measurement
    const newNodeTransform = newNode.getComponent(UITransform)
    newNodeTransform.setContentSize(200, 200)

    // add to different node
    this.photoBorder.node.guardian.addChild(newNode)
});

Please assist me resolve this downside

Thanks very a lot!



Is the picture handle appropriate? Is the picture format?
Or add this code: newNode.layer = Layers.Enum.UI_2D;

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments