Sunday, November 27, 2022
HomeGame DevelopmentEasy methods to create Sprite Node with Picture from URL in Cocos...

Easy methods 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 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.mother or father.addChild(newNode)
});

Please assist me resolve this drawback

Thanks very a lot!



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

thank @Koei ,
I missed newNode.layer = Layers.Enum.UI_2D; in my code

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments