Monday, August 29, 2022
HomeGame DevelopmentChange Sprite Image Runtime programmatically - Cocos Creator

Change Sprite Image Runtime programmatically – Cocos Creator


I’m attempting to vary spriteframe ontouch occasion utilizing the code given in Documentation.
But on faucet the spriteframe goes clean. utilizing CocosCreator 3.5.2
Getting this error on Console.

      const self = this;
      const url="property/NewImage";
      assets.load(url, ImageAsset, (err: any, imageAsset) => {
        const sprite = this.getComponent(Sprite);
        const spriteFrame = new SpriteBody();
        const tex = new Texture2D();
        tex.picture = imageAsset;
        spriteFrame.texture = tex;
        sprite.spriteFrame = spriteFrame;
      });

https://docs.cocos.com/creator/3.5/handbook/en/asset/sprite-frame.html?h=body

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments