Sunday, November 20, 2022
HomeGame DevelopmentThe right way to create Sprite Node with Picture from URL in...

The right way to create Sprite Node with Picture from URL in Cocos Creator V3? – Cocos Creator


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

// distant load picture
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.mother or father.addChild(newNode)
});

Please assist me resolve this downside

Thanks very a lot!


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments