Proper way to run Cocos studio animation

Here’s the problem: suppose I created a custom node and added some animation to it, then I create this node. How do I run my animation? The best solution I’ve found so far is to load ActionTimeline from csb:

CSLoader::createTimeline("path");

It seems to be a wrong way sinse I’ve already loaded entire csb while creating the node. Shouldn’t I be able to get timelines directly from my custom node?

It’s ok to read a csb file twice to create node and timeline action since CSLoader caches data automatically.
Go to cpp-tests\Classes\ExtensionsTest\CocoStudioActionTimelineTest\ActionTimelineTestScene.cpp.

Data data = FileUtils::getInstance()->getDataFromFile("ActionTimeline/DemoPlayer.csb");
Node* node = CSLoader::createNode(data);
ActionTimeline* action = CSLoader::createTimeline(data, "ActionTimeline/DemoPlayer.csb");
node->runAction(action);
action->gotoFrameAndPlay(0);

It’s may be okay in performance side… But it’s not okay in convenience usage and good API side. Timelines and nodes are tightly coupled. Sometimes node may be created in one place and animation may be required in other place. Sometimes node can be loaded as part of scene hierarchy. There is no common way for handling these situation, when we don’t know file name (actually, there is some workaround with action tags).

Not bad solution would be to add AnimationComponent or TimelineComponent that should be always available.

You can alway create timeline action from another file. But you will not like it. Let’s say, you have a nodeBody.csb and a moveAction.csb. Once you add anything to nodeBody, you need to add them manully to action file.

+1!!

That’s the point. Just an example: I have a bunch of animated nodes, which are needed to construct, say, a tool palette. If I was able to run animations without referencing actual csb, I would be able to compose entire palette in CocosStudio, but I cannot. I’ve forced to hardcode dozens of filepaths, since it’s impossible to scan directory with FileUtils in order to generate this list of filenames.

I’ve seen pretty weird silution, by the way, which actually appears to work, but it looks ugly:

cocostudio::timeline::ActionTimeline* pActionTimeline = (cocostudio::timeline::ActionTimeline*)pNode->getActionByTag(pNode->getTag());

Here’s a discussion