Cocos2dx之文字显示

Cocos2dx之文字显示,第1张

概述C++之旅 QQ群:201704374 伸手党的救星,1T资料等你来战 一、显示文字的控件 1、CCLabel 2、CCLabelTTF 3、CCLabelAtlas 二、文字显示实现 1、CCLabel #ifndef __T07CCLabel_H__#define __T07CCLabel_H__#include "cocos2d.h"USING_NS_CC;class T07CCL

C++之旅 QQ群:201704374

伸手党的救星,1T资料等你来战



一、显示文字的控件

1、cclabel

2、cclabelTTF

3、cclabelAtlas


二、文字显示实现

1、cclabel

#ifndef __T07cclabel_H__#define __T07cclabel_H__#include "cocos2d.h"USING_NS_CC;class T07cclabel : public cclayer{public:	static CCScene* scene();	CREATE_FUNC(T07cclabel);	bool init();	bool cctouchBegan(CCtouch *ptouch,CCEvent *pEvent);	voID cctouchmoved(CCtouch *ptouch,CCEvent *pEvent);};#endif

#include "T07cclabel.h"static const char* _Font[] = {	"AppleGothic","HiraKakuProN-W6","HiraKakuProN-W3","MarkerFelt-Thin","STHeitiK-Medium","STHeitiK-light","TimesNewRomanPSMT","Helvetica-Oblique","Helvetica-Boldoblique","Helvetica","Helvetica-Bold","TimesNewRomanPS-BoldMT","TimesNewRomanPS-BoldItalicMT","TimesNewRomanPS-ItalicMT","Verdana-Bold","Verdana-BoldItalic","Verdana","Verdana-Italic","Georgia-Bold","Georgia","Georgia-BoldItalic","Georgia-Italic","ArialRoundedMTBold","TrebuchetMS-Italic","TrebuchetMS","Trebuchet-BoldItalic","TrebuchetMS-Bold","STHeitiTC-light","STHeitiTC-Medium","GeezaPro-Bold","GeezaPro","CourIEr","CourIEr-Boldoblique","CourIEr-Oblique","CourIEr-Bold","ArialMT","Arial-BoldMT","Arial-BoldItalicMT","Arial-ItalicMT","STHeitiJ-Medium","STHeitiJ-light","ArialHebrew","ArialHebrew-Bold","CourIErNewPS-BoldMT","CourIErNewPS-BoldItalicMT","CourIErNewPSMT","Thonburi-Bold","AmericanTypewriter","AmericanTypewriter-Bold","STHeitiSC-Medium","STHeitiSC-light","HelveticaNeue","HelveticaNeue-Bold","Zapfino"};CCScene* T07cclabel::scene(){	CCScene* scene = CCScene::create();	T07cclabel* layer = T07cclabel::create();	scene->addChild(layer);	return scene;}bool T07cclabel::init(){	cclayer::init();	CCSize winSize = CCDirector::sharedDirector()->getWinSize();	#if 0	cclabelTTF* ttf = cclabelTTF::create("Content","Arial",24);	addChild(ttf);	ttf->setposition(ccp(winSize.wIDth/2,winSize.height/2));#endif	int count = sizeof(_Font)/sizeof(*_Font);	for (int i =0; i < count; i++)	{		cclabelTTF* ttf = cclabelTTF::create(_Font[i],_Font[i],24);		addChild(ttf);		ttf->setposition(ccp(winSize.wIDth/2,i * 24 + 12));	}	settouchEnabled(true);	settouchMode(kCCtouchesOneByOne);	return true;}bool T07cclabel::cctouchBegan(CCtouch *ptouch,CCEvent *pEvent){	return true;}voID T07cclabel::cctouchmoved(CCtouch *ptouch,CCEvent *pEvent){	this->setpositionY(getpositionY() + ptouch->getDelta().y);}

2、cclabelTTF

3、cclabelAtlas

#ifndef __T08cclabelAtlas_H__#define __T08cclabelAtlas_H__// cclabelTTF cclabelAtlas cclabelBMFont#include "cocos2d.h"USING_NS_CC;class T08cclabelAtlas : public cclayer{public:	static CCScene* scene();	CREATE_FUNC(T08cclabelAtlas);	bool init();};#endif
#include "T08cclabelAtlas.h"CCScene* T08cclabelAtlas::scene(){	CCScene* s = CCScene::create();	T08cclabelAtlas* layer = T08cclabelAtlas::create();	s->addChild(layer);	return s;}bool T08cclabelAtlas::init(){	cclayer::init();	CCSize winSize = CCDirector::sharedDirector()->getWinSize();	cclabelAtlas* atlas = cclabelAtlas::create("123abb123","labelatlasimg.png",24,32,'0');	addChild(atlas);	atlas->setposition(ccp(winSize.wIDth / 2,winSize.height / 2));//	CCSprite* sp = CCSprite::create("Closenormal.png");//	addChild(sp);//	sp->setposition(ccp(winSize.wIDth / 2,winSize.height / 2));	return true;}


三、应用场合

1、cclabel

固定不变是文字显示

2、cclabelTTF

每个文字可以是精灵,经行精灵 *** 作

3、cclabelAtlas

分数显示

总结

以上是内存溢出为你收集整理的Cocos2dx之文字显示全部内容,希望文章能够帮你解决Cocos2dx之文字显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1066796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存