I’m dealing with a problem in Cocos Creator 3.8.2 when setting a Tiled Sprite dynamically at runtime. Initially, I used to be getting the error:
Uncaught TypeError: Can not learn property ‘vb’ of null
Challenge Particulars:
- I’ve a Sprite element with the Sort set to “Tiled” and Dimension Mode set to “Customized”.
- The SpriteFrame is ready dynamically utilizing a downloaded picture.
- The node’s UITransform measurement is ready to 576×1024, however the trimmed measurement of the SpriteFrame is 128×128.
- If I modify the Sprite Sort to “Easy”, the whole lot works tremendous.
- If I modify Dimension Mode to “Trimmed”, it additionally works, however this modifies the node measurement, which I don’t need.
Code:
var self = this;
cc.assetManager.loadRemote(cc.native.fileUtils.getWritablePath()+savePath_ + "https://discussion board.cocosengine.org/" + imageName_, operate (err, imageAsset) {
}
self.setTextureToSprite("picture.jpg", imageAsset, self.MySprite);
Solely after I used a daily operate (operate() {}
) with ‘this’ immediately, the problem was resolved:
cc.assetManager.loadRemote(cc.native.fileUtils.getWritablePath()+savePath_ + "https://discussion board.cocosengine.org/" + imageName_, operate (err, imageAsset) {
}
this.setTextureToSprite("picture.jpg", imageAsset, this.MySprite);
Why does self = this;
trigger a problem in Cocos 3.8.2 when utilizing a Tiled Sprite?
Why does this concern happen solely with a “Tiled” Sprite and “Customized” Dimension Mode, however not with “Easy” or “Trimmed”?
Why will we generally use var self = this;
in Cocos TypeScript? Is it nonetheless essential in newer Cocos variations?