Sunday, December 4, 2022
HomeGame DevelopmentDynamic animation in runtime | Error in getSpriteFrames() methodology - Cocos Creator

Dynamic animation in runtime | Error in getSpriteFrames() methodology – Cocos Creator


Cocos Creator Model – 2.4.7
Intent – To load a spriteAtlas from the server and dynamically animate it utilizing code.
I used cc.assetManager.loadRemote() to get the .plist file and was attempting to get every frames(SpriteFrame) from that .plist file.
However getting error on this methodology – .getSpriteFrames()
The Error – Simulator: ERROR: Uncaught TypeError: sp.getSpriteFrame isn’t a perform, location: dst/property/Script/Animation/DynamicAnimation.js:0:0
The Code :-
CreateSprite()
{
let fileFullPath = jsb.fileUtils.getWritablePath() + “sprSht2-Splash-loadingAnim.plist”;
// sprSht2-Splash-loadingAnim.plist – is my file title
cc.assetManager.loadRemote(fileFullPath, cc.SpriteAtlas, perform (err, sp:cc.SpriteAtlas)
{
if(err)
err);
return;

else
{
var fa = sp.getSpriteFrames();
//code getting caught on the above line.
if(!fa)
{
cc.log(“error in fa”);
}
else
{
cc.log(“No error in fa”)
}
return;
}
});
}
Any leads concerning the question is extremely appreciated.


loadRemote is for loading distant sources similar to picture, audio clip or textual content. So, your plist file is being handled as a textual content. Attempt to console.log the sp object.

I additionally seen that you simply had been utilizing machine location moderately than a distant url. in that case, discuss with the next codes to load an atlas.

// load SpriteAtlas, and get one in every of them SpriteFrame
// Be aware Atlas useful resource file (plist) normally of the identical title and an image file (PNG) positioned in a listing,
// So ought to must within the second parameter specifies the useful resource sort.
cc.loader.loadRes("check property/sheep", cc.SpriteAtlas, perform (err, atlas) {
    var body = atlas.getSpriteFrame('sheep_down_0');
    sprite.spriteFrame = body;
});

In case you nonetheless need to load from a distant server for animation, that is how I did

  • create my an personal property file (frames, pace, pictures places and so forth.)
  • obtain the property file
  • obtain particular person pictures from definition utilizing loadRemote
  • create an animation utilizing the downloaded pictures and property

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments