cocos2d-x 3.0 using label to achieve typewriter effect
Initialize the label
content = "This world I have come, let the storm swirl." This is your commitment to love, brother 12345, brother a implementing, brother oceans Deep, brother in the afterlife a mother. Brothers meet, three bowls of wine, the brother of an min, the eternal boast. ";
n = 3;//0~3 to obtain a Chinese character
int contentlength = Content.length ();
label = Label::create ();
Label->setstring ("");
Label->setsystemfontsize (+);
Label->setposition (VISIBLESIZE.WIDTH/5, VISIBLESIZE.HEIGHT/2);
Label->setanchorpoint (VEC2 (0, 1));//Set anchor point, print from left to right
label->setdimensions (+);
This->addchild (label);
This->schedule (Schedule_selector (Helloworld::showfont), 0.1f);
void Helloworld::showfont (float dt) {
<span style= "White-space:pre" > </span>std::string str = Content.substr (0, this->n);
This->label->setstring (str);
n = n + 3;
if (n > Content.length ()) {
this->unschedule (Schedule_selector (Helloworld::showfont));
}
}