Cocos2d-x LabelTTF和TextFieldTTF

前端之家收集整理的这篇文章主要介绍了Cocos2d-x LabelTTF和TextFieldTTF前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一:LabelTTF

是一个文本输出展示控件 例子:

	LabelTTF *laber = LabelTTF::create();
	laber->setString("Hello World");
	laber->setFontSize(36);
	laber->setPosition(size.width/2,size.height/2);
	addChild(laber);

二:TextFieldTTF

是文本输出控件 例子:

	Size visibleSize = Director::getInstance()->getVisibleSize();
	TextFieldTTF *tf = TextFieldTTF::textFieldWithPlaceHolder("在这里输入","宋体",20);
	tf->setPosition(visibleSize.width/2,visibleSize.height/2);
	addChild(tf);
	auto listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = [tf](Touch *t,Event *event){
		if(tf->getBoundingBox().containsPoint(t->getLocation()))
		{
			tf->attachWithIME();
		}else
		{
			tf->detachWithIME();
		}

		return false;
	};
	Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraPHPriority(listener,tf);
原文链接:https://www.f2er.com/cocos2dx/346509.html

猜你在找的Cocos2d-x相关文章