Hi Everyone,
I’m trying to dynamically change the spriteframe of one of my nodes using the following code:
var sprite = newAchievementObject.achievementSymbol.getComponent(cc.Sprite);
sprite.spriteFrame = achievementSymbol;
“achievementSymbol” is defined directly from the canvas and is a .png file in the resources folder; however, I get the following error:
Uncaught TypeError: this._spriteFrame.getTexture is not a function
I’m running Cocos Creator 2.4.5.
Does anyone know what causes an error like this? Thanks for your help!
Log Output:
Uncaught TypeError: this._spriteFrame.getTexture is not a function
at cc_Sprite._updateMaterial (cocos2d-js-for-preview.js:33289)
at cc_Sprite._applySpriteFrame (cocos2d-js-for-preview.js:33318)
at cc_Sprite.set [as spriteFrame] (cocos2d-js-for-preview.js:33169)
at Menu.addAchievement (eval at (quick_compile.js:238), :1370:24)
at Menu.addRootAchievements (eval at (quick_compile.js:238), :1261:14)
at Menu.onLoad (eval at (quick_compile.js:238), :574:10)
at eval (eval at createInvokeImpl (cocos2d-js-for-preview.js:27772), :3:65)
at CCClass._invoke (cocos2d-js-for-preview.js:27776)
at CCClass.invoke (cocos2d-js-for-preview.js:27726)
at CCClass.activateNode (cocos2d-js-for-preview.js:39342)