已经学了好几节了,现在把UI系统的笔记再整一下。
Cocos2D-X UI系统我学习的有:字体、标签、菜单、进度条、计时器。
1、字体
2、标签
3、菜单
4、进度条
5、计时器
其实小牛在写这个笔记的时候,已经把cocos2dx的基础篇学习完了,现在就当是做一个基础巩固。
其实小牛是个菜鸟……
![尴尬](http://static.blog.csdn.net/xheditor/xheditor_emot/default/awkward.gif)
小牛在认识系统中基础UI的时候,用了几个字体标签的组件:
<span style="white-space:pre"> </span>CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* ttfFont = CCLabelTTF::create("Hello World", "Arial", 24);
addChild(ttfFont);
ttfFont->setPosition(ccp(s.width/2,s.height/2));
ttfFont->setString("Hello cocos2dx");
ttfFont->setColor(ccc3(255,0,0));
ttfFont->setScale(3.0f);
ttfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelBMFont* bmfFont = CCLabelBMFont::create("1234", "fonts/bitmapFontChinese.fnt");
addChild(bmfFont);
bmfFont->setPosition(ccp(s.width/2,s.height/2));
bmfFont->setColor(ccc3(255,0,0));
//bmfFont->setScale(3.0f);
//bmfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelAtlas* atlasFont = CCLabelAtlas::create("123","fonts/labelatlas.png",32,32,96);
addChild(atlasFont);
atlasFont->setPosition(ccp(s.width/2,s.height/2));
其中本来想写中文,可发现中文显示出来的都是乱码,后来在百度上查了一下中文的问题,发现是个很麻烦的问题,解决办法点这里。
<span style="white-space:pre"> </span>CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* ttfFont = CCLabelTTF::create("Hello World", "Arial", 24);
addChild(ttfFont);
ttfFont->setPosition(ccp(s.width/2,s.height/2));
ttfFont->setString("Hello cocos2dx");
ttfFont->setColor(ccc3(255,0,0));
ttfFont->setScale(3.0f);
ttfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelBMFont* bmfFont = CCLabelBMFont::create("1234", "fonts/bitmapFontChinese.fnt");
addChild(bmfFont);
bmfFont->setPosition(ccp(s.width/2,s.height/2));
bmfFont->setColor(ccc3(255,0,0));
//bmfFont->setScale(3.0f);
//bmfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelAtlas* atlasFont = CCLabelAtlas::create("123","fonts/labelatlas.png",32,32,96);
addChild(atlasFont);
atlasFont->setPosition(ccp(s.width/2,s.height/2));
小牛也是水平太low了,没有实现就往下学习了。
小牛在csdn这个强大的blog中找到各种优秀文章,在此就做一个记录咯!
进度条的使用-> 点这里。
小牛也是着急,这做个小游戏怎么这么难……
![奋斗](http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif)
![奋斗](http://static.blog.csdn.net/xheditor/xheditor_emot/default/struggle.gif)
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* ttfFont = CCLabelTTF::create("Hello World", "Arial", 24);
addChild(ttfFont);
ttfFont->setPosition(ccp(s.width/2,s.height/2));
ttfFont->setString("Hello cocos2dx");
ttfFont->setColor(ccc3(255,0,0));
ttfFont->setScale(3.0f);
ttfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelBMFont* bmfFont = CCLabelBMFont::create("1234", "fonts/bitmapFontChinese.fnt");
addChild(bmfFont);
bmfFont->setPosition(ccp(s.width/2,s.height/2));
bmfFont->setColor(ccc3(255,0,0));
//bmfFont->setScale(3.0f);
//bmfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelAtlas* atlasFont = CCLabelAtlas::create("123","fonts/labelatlas.png",32,32,96);
addChild(atlasFont);
atlasFont->setPosition(ccp(s.width/2,s.height/2));
用起来有些不顺手,毕竟第一次使用……
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelTTF* ttfFont = CCLabelTTF::create("Hello World", "Arial", 24);
addChild(ttfFont);
ttfFont->setPosition(ccp(s.width/2,s.height/2));
ttfFont->setString("Hello cocos2dx");
ttfFont->setColor(ccc3(255,0,0));
ttfFont->setScale(3.0f);
ttfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelBMFont* bmfFont = CCLabelBMFont::create("1234", "fonts/bitmapFontChinese.fnt");
addChild(bmfFont);
bmfFont->setPosition(ccp(s.width/2,s.height/2));
bmfFont->setColor(ccc3(255,0,0));
//bmfFont->setScale(3.0f);
//bmfFont->setRotation(45.f);
CCSize s = CCDirector::sharedDirector()->getWinSize();
CCLabelAtlas* atlasFont = CCLabelAtlas::create("123","fonts/labelatlas.png",32,32,96);
addChild(atlasFont);
atlasFont->setPosition(ccp(s.width/2,s.height/2));