Cocostudio: how to play animation in that case?

How to play animation if i don’t know from what file that widget was created?

For example, i have created custom Button. And for that Button i have created few csd files - round button, square button, image button. So unlike default UIButton my custom button is driven by csd and animations for each state (normal, selected, disabled).

On some scene i added buttons of different types (via CocoStudio). How i can play animations for these buttons if i can’t know which csd file is correspond to it (round_button.csb, square_button.csb,…). So i can’t create ActionTimeline for it.

E.g. in cocosbuilder i can do this:

dynamic_cast<CCBAnimationManager *>(button->getUserObject())->runAnimation("Selected");

But in cocostudio to create timeline i should know from which file that Button was created. But button not created programmatically, so i don’t know it…

cocostudio::timeline::ActionTimelineCache::getInstance()->createAction("??????????????");

Haven’t tested it yet, but seems like in that case timelines are launched as action automatically, with tag equal to node tag. And because ActionTimeline actually infinite action (them not removing automatically, only manually) it can be obtained with next code:

dynamic_cast<ActionTimeline *>(getActionByTag(getTag());

Though it would be better to have one way to obtaining ActionTimeline for all cases (for example via ExtComponent);

Nice find! I always wondered why my sprites have 1 running action…

I just wanted to use it and it doesn’t work. getActionByTag(getTag()) returns NULL.

Just checked it, should work fine.

Are you trying this on the node, that was added as FileNode inside your scene?
This action not run automatically on csb-nodes loaded programmatically, but only on FileNodes loaded as part of nodes hierarchy.

I.e.
I have MainScene.csd and Item.csd
I added Item.csd to MainScene.csd

Then in code:

auto scene = CSLoader::createNode("MainScene.csb");
auto itemNode = scene->getChildByName("FileNode_1");
auto itemAction = itemNode->getActionByTag(itemNode->getTag()); //exist
auto sceneAction = scene->getActionByTag(scene->getTag()); //not exist, ActionTimeline should be created manually.... why?!

Now I see. That explains everything. Yeah, I used CSLoader to get a node and it didn’t have any animations running.