cocos2dx打字效果
Label *label;
std::string content;
创建:
content = "这世界我来了,任凭风暴漩涡。这是你爱的承诺,兄弟一二三四五,兄弟个十百千万,兄弟情 深似海深,兄弟来生一个妈!兄弟相逢,三碗酒,兄弟安民,万世夸!富士康的减肥看电视剧的是否健康的设计费第三方绝对是第三方会计阿斯顿反馈";
n = 3;// 0~3来获得一个中文字符
label = Label::create();
label->setString("");
label->setColor(Color3B::WHITE);
label->setSystemFontSize(40);
label->setPosition(Vec2(100, 500));
label->setAnchorPoint(Vec2(0, 1));//设置锚点,从左向右打印
label->setDimensions(800, 400);
this->addChild(label);
this->schedule(schedule_selector(WelcomeView::showFont),0.1f);
显示:
void XXX::showFont(float dt)
{
std::string str = content.substr(0, this->n);
this->label->setString(str);
n = n + 3;
if (n > content.length())
{
this->unschedule(schedule_selector(XXX::showFont));
}
}
去空格:
static void trim( std::string& str, bool left = true, bool right = true );
void trim(string& str, bool left, bool right)
{
static const string delims = " \t\r";
if(right)
str.erase(str.find_last_not_of(delims)+1); // trim right
if(left)
str.erase(0, str.find_first_not_of(delims)); // trim left
}