Loading .csb and playing it's timeline

Hi. I’m trying to loading a .csb file via Director::getInstance()->pushScene(MyScene::createScene());. The scene loads but the timeline doesn’t play. I’ve tried everything except the thing that works. The csb type is a Node with 30 frames of animation. I’m completely stumped. Here is one of the many things I’ve tried.

// on "init" you need to initialize your instance
bool RollUp_5InARow::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    auto rootNode = CSLoader::createNode("Machines/RollUps/RollUp_5InARow.csb");
    auto action = dynamic_cast<cocostudio::timeline::ActionTimeline*>(rootNode->getActionByTag(rootNode->getTag()));
    action->gotoFrameAndPlay(0);
    rootNode->runAction(action);
    this->addChild(rootNode);
            
    return true;
}

I think you should do this:

auto rootNode = CSLoader::createNode(“Machines/RollUps/RollUp_5InARow.csb”);
ActionTimeline* action = CSLoader::createTimeline(“Machines/RollUps/RollUp_5InARow.csb”);
action->gotoFrameAndPlay(0);
rootNode->runAction(action);

1 Like

Thanks nick3d that works great. I was pulling my hair out trying to figure this out.

auto rootNode = CSLoader::createNode("Machines/RollUps/RollUp_5InARow.csb");
this->addChild(rootNode);
cocostudio::timeline::ActionTimeline* action = CSLoader::createTimeline("Machines/RollUps/RollUp_5InARow.csb");
action->gotoFrameAndPlay(0);
rootNode->runAction(action);
1 Like