runAction Issue: I want show a counting sequence like "3,2,1,Go" but only the "Go" is shown

I want show a counting sequence like “3,2,1,Go” but only the “Go” is shown.
What is wrong?

Action* pScaleCounter = Sequence::create(ScaleTo::create(1.0f, 5.0f), nullptr);

	auto labelCounter = Label::createWithTTF("3", "fonts/arial.ttf", 150);
	labelCounter->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
	this->addChild(labelCounter, 10);

	labelCounter->runAction(pScaleCounter);
	labelCounter->setScale(1.0);
	labelCounter->setString("2");
	labelCounter->runAction(pScaleCounter->clone());
	labelCounter->setScale(1.0);
	labelCounter->setString("1");
	labelCounter->runAction(pScaleCounter->clone());
	labelCounter->setScale(1.0);
	labelCounter->setString("GO");
	labelCounter->runAction(pScaleCounter->clone());

That’s because you immediately change label text using setString. You need to do this inside animation.

Action* pScaleCounter = Sequence::create(ScaleTo::create(1.0f, 5.0f), CallFunc::create([&, labelCounter](){

    auto str = labelCounter->getString();
    if(str == "3") str = "2";
    else if(str == "2") str = "1";
    else if(str == "1") str = "GO";
    labelCounter->setString(str); 

}
), nullptr);
1 Like

Thanks. Thats help me a lot.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.