Greetings.
A background. I want to show text in the game using different animations, kinda the talking boxes of RPG games.
Here is the implementation.
In the header:
void UpdateFunction(float dt);
In the CPP file:
First, I call a function with a schedule, with a timeframe of 0.3 secs:
schedule(schedule_selector(MainMenuScene::UpdateFunction), 0.3);
I create a global variable so I can use it to pass through each letter, without assigning the variable inside the function.
int currentLetter = 0;
Now, the function runs like this:
First, I create the label and put it in a position, then add it to the scene.
Label *set1 = Label::createWithTTF("Welcome home", "Marker Felt.ttf", 100);
set1->setPosition(Point(400, 400));
addChild(set1);
Now, I get each letter of the label, create the animation and apply it to each letter.
auto WChar = (Sprite *)set1->getLetter(currentLetter);
auto jump = JumpBy::create(0.5f, Vec2::ZERO, 60, 1);
WChar->runAction(jump);
Finally, I add one to the global currentLetter.
currentLetter ++;
If you run the code, this is what happens:
- The text appears on screen.
- Each letter is animated correctly, but the whole text remains in the background.
- When the animation ends, (obviously) gives me an error because the ++ of the last letter doesn’t exist.
For this last one, I tried to do this but it didn’t work:
if (currentLetter >= set1->getStringLength())
{
return;
}
So, what I am looking is:
- How can I make it so each letter appears one by one, without showing what is the next one? (it might be something to do with the opacity I believe)
- How can I close the function once it finishes all the letters?
Mainly that.
Thanks everyone for your support.