cocos2d-x 3.0 用label来实现打字机效果

cocos2d-x 3.0  用label来实现打字机效果

 //初始化label
content = "这世界我来了,任凭风暴漩涡。这是你爱的承诺,兄弟一二三四五,兄弟个十百千万,兄弟情深似海深,兄弟来生一个妈!兄弟相逢,三碗酒,兄弟安民,                 万世夸!";
n = 3;// 0~3来获得一个中文字符
int contentLength = content.length();
label = Label::create();
label->setString("");
label->setSystemFontSize(40);
label->setPosition(visibleSize.width /5, visibleSize.height / 2);
label->setAnchorPoint(Vec2(0, 1));//设置锚点,从左向右打印
label->setDimensions(800, 400);
this->addChild(label);
this->schedule(schedule_selector(HelloWorld::showFont),0.1f);

void HelloWorld::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(HelloWorld::showFont));
	}
}

 
  

你可能感兴趣的:(cocos2d-x 3.0 用label来实现打字机效果)