Curious about ActionManager and

How does cocostudio::ActionManagerEx::getInstance()->playActionByName();
know which node to animate?
I have:

Layout *layout = dynamic_cast<Layout*>(cocostudio::GUIReader::shareReader()->widgetFromJsonFile("Dialog_1.json"));
cocostudio::ActionManagerEx::getInstance()->playActionByName("Dialog_1.json", "Animation1");

It works fine but i wonder how does it know which node to animate “layout”

Take a look into cocostudio/CCSGUIReader.cpp

Widget* WidgetPropertiesReader0300::createWidget(const rapidjson::Value& data, const char* fullPath, const char* fileName)

When you are loading in the json definition file it creates the widgets and inits the ActionManagerEx with them:

ActionManagerEx::getInstance()->initWithDictionary(fileName,actions,rootWidget);

Which creates the actions itself and binds/links them to the widgets/nodes.

cocostudio::ActionManagerEx::getInstance()->playActionByName("Dialog_1.json", "Animation1");

This call looks up the “Dialog_1.json” actions as key from the action dictionary in the ActionManagerEx and calls the “Animation1”.
As it has created the actions and linked the nodes beforehand it “knows” which node to animate in “layout”.

1 Like

It’s the magic of associative containers!
http://www.cplusplus.com/reference/map/map/

and how do I remove / release widget from GUIReader?

There are no member functions in GuiReader for that.

By removing it from the layout. Layout is the root widget aka the parent of all other widgets:

void removeChild (Node *child, bool cleanup=true);

First you get the pointer for your node, which you want to remove and than call the above function with that pointer.