本文整理汇总了C++中CCLabelTTF::setHorizontalAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ CCLabelTTF::setHorizontalAlignment方法的具体用法?C++ CCLabelTTF::setHorizontalAlignment怎么用?C++ CCLabelTTF::setHorizontalAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCLabelTTF
的用法示例。
在下文中一共展示了CCLabelTTF::setHorizontalAlignment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeAChoice
void StoryWorld::makeAChoice(CCObject *sender) {
int choice = ((CCNode *)sender)->getTag();
if (current == '3') {
switch (choice) {
case fChoice: {
// 显示宣传单一
cout << "xuanchuan " << endl;
removeChildByTag(2);
removeChildByTag(3);
CCSprite *blackBG = CCSprite::create(BLACK_IMG_PATH);
blackBG->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2));
blackBG->setScale(1);
blackBG->setTag(21);
addChild(blackBG, 2);
// TODO
CCLabelTTF *xuanchuan = CCLabelTTF::create();
xuanchuan->setPosition(ccp(0, 40));
xuanchuan->setHorizontalAlignment(kCCTextAlignmentLeft);
xuanchuan->setAnchorPoint(CCPointZero);
xuanchuan->setDimensions(CCSizeMake(1100, 0));
xuanchuan->setTag(22);
addChild(xuanchuan, 3);
// 关闭按钮
CCMenuItemImage *start = CCMenuItemImage::create(LEAFLET_IMG_PATH,
LEAFLET_IMG_PATH,
this,
menu_selector(StoryWorld::menuLeafletsCloseCallback));
start->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width-40, CCDirector::sharedDirector()->getVisibleSize().height-40));
//菜单
CCMenu* pMenu = CCMenu::create(start, NULL);
pMenu->setPosition(CCPointZero);
pMenu->setTag(23);
addChild(pMenu, 4);
}
return;
case sChoice:
default:{
current+=1;
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320, kResolutionExactFit);
CCDirector::sharedDirector()->popScene();
}
return;
}
}
char fileName[8] = "Fin ";
switch (choice) {
case fChoice:
fileName[3]='1';
break;
case sChoice:
fileName[3]='2';
break;
case tChoice:
fileName[3]='3';
break;
default:
break;
}
reader.ChangeFile(cocos2d::CCFileUtils::sharedFileUtils()->fullPathForFilename(fileName));
removeChildByTag(2);
removeChildByTag(3);
setTouchEnabled(true);
avgGame();
}
示例2: init
bool StoryWorld::init() {
if ( !CCLayer::init() ) {
return false;
}
char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"};
char play[20] = SCRIPT_PATH;
current=sGlobal->mapState->storyCnt+'0';
play[SCRIPT_PATH_LEN] = current;
reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play));
this->setTouchEnabled(true);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
char bg_name[30] = "" ;
char bg_num[4]="";
sprintf(bg_num, "%c00", current);
sprintf(bg_name, BGNAME_IMG_PATH, bg_num);
CCSprite *pBackground = CCSprite::createWithTexture(GET_TEXTURE(bg_name));
//CCSprite* pBackground = CCSprite::create(bg_name);
pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
pBackground->setScale(1);
pBackground->setTag(108);
addChild(pBackground, 0);
CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH);
dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2));
dialogBox->setOpacity(220);
addChild(dialogBox,1);
CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40);
pName->setTag(101);
pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height));
pName->setAnchorPoint(CCPointZero);
addChild(pName, 1);
CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40);
pLabel->setTag(100);
pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height));
pLabel->setAnchorPoint(CCPointZero);
pLabel->setDimensions(CCSizeMake(1100, 0));
pLabel->setHorizontalAlignment(kCCTextAlignmentLeft);
addChild(pLabel, 1);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH);
CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::createWithTexture(GET_TEXTURE(VDRAWING_IMG_PATH));
spriteBatch->setTag(102);
addChild(spriteBatch, 0);
spriteBatch->setPosition(CCPointZero);
CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png");
leftSprite->setScale(0.8);
leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.6, leftSprite->getContentSize().height/2 *0.8));
leftSprite->setTag(1);
leftSprite->setOpacity(0);
spriteBatch->addChild(leftSprite, 0);
CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png");
//rightSprite->setScale(0.8);
rightSprite->setPosition(ccp(800, 130));
rightSprite->setTag(2);
rightSprite->setOpacity(0);
spriteBatch->addChild(rightSprite, 0);
avgGame();
return true;
}
示例3: initTopBar
// 初始化顶部bar
void MessageView::initTopBar(CCSize winSize)
{
////////////////////////////////////////////////////////////////////////////////////////////////////
// topBarNode 背景
CCSprite* topBarBg = CCSprite::create("bg_nav_top.png") ;
topBarBg->setAnchorPoint(ccp(0.5, 0)) ;
topBarBg->setPosition(ccp(winSize.width/2, 0)) ;
const float topBar_height = topBarBg->getContentSize().height ;
// 顶部条信息 //////////////////////////////////////////////////////////////////////////////////////
this->topBarNode = CCNode::create() ;
this->topBarNode->setContentSize(CCSizeMake(winSize.width, topBar_height)) ;
this->topBarNode->setAnchorPoint(ccp(0, 0)) ;
this->topBarNode->setPosition(ccp(0, winSize.height - topBar_height)) ;
this->addChild(this->topBarNode, 0, 1) ;
// 将topBarNode背景加入到topBarNode
this->topBarNode->addChild(topBarBg, 0 ) ;
///////////////////////////// 左侧布局 //////////////////////////
CCNode* leftNode = CCNode::create() ;
leftNode->setContentSize(CCSizeMake(300, topBar_height)) ;
leftNode->setAnchorPoint(ccp(0, 0.5)) ;
leftNode->setPosition(ccp(30, topBar_height/2)) ;
this->topBarNode->addChild(leftNode, 1) ;
// 头像
CCSprite* headPortraitSprite = CCSprite::create("user/head_default_f2.png") ;
headPortraitSprite->setAnchorPoint(ccp(0, 0)) ;
headPortraitSprite->setPosition(ccp(0, 10)) ;
headPortraitSprite->setScale(0.8) ;
leftNode->addChild(headPortraitSprite) ;
// 昵称
CCLabelTTF* nikeNameLabel = CCLabelTTF::create("昵称:我是主角", "font01.ttf", 22.0f) ;
// nikeNameLabel->setColor(ccc3(191, 173, 111)) ;
nikeNameLabel->setAnchorPoint(ccp(0, 0)) ;
nikeNameLabel->setPosition(ccp(70, topBar_height/2+2)) ;
nikeNameLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式
nikeNameLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式
leftNode->addChild(nikeNameLabel) ;
// 金币
CCLabelTTF* goldCoinLabel = CCLabelTTF::create("金币:10000", "font01.ttf", 22.0f) ;
goldCoinLabel->setAnchorPoint(ccp(0, 1)) ;
goldCoinLabel->setPosition(ccp(70, topBar_height/2)) ;
goldCoinLabel->setHorizontalAlignment(kCCTextAlignmentLeft) ; // 水平对齐方式
goldCoinLabel->setVerticalAlignment(kCCVerticalTextAlignmentCenter) ; // 垂直对齐方式
leftNode->addChild(goldCoinLabel) ;
// 信息
CCSprite* titleMsg = CCSprite::create("icon_title_message.png") ;
titleMsg->setAnchorPoint(ccp(0.5, 0.5)) ;
titleMsg->setPosition(ccp(winSize.width/2, topBar_height/2)) ;
this->topBarNode->addChild(titleMsg, 1) ;
// 分割线
CCSprite* spliteLineLeft = CCSprite::create("icon_top_nav_splite.png") ;
spliteLineLeft->setAnchorPoint(ccp(0, 1)) ;
spliteLineLeft->setPosition(ccp(winSize.width/3+10, topBar_height)) ;
this->topBarNode->addChild(spliteLineLeft, 1) ;
// 分割线
CCSprite* spliteLineRight = CCSprite::create("icon_top_nav_splite.png") ;
spliteLineRight->setAnchorPoint(ccp(0, 1)) ;
spliteLineRight->setPosition(ccp(winSize.width*2/3-20, topBar_height)) ;
this->topBarNode->addChild(spliteLineRight, 1) ;
/////////////////////////////////////////////////////////////////////////////////////////////////
/****************************** 菜单选项 ********************************************************/
// 右侧menu
const float right_width = 200 ;
const float item_width = 55 ;
// 礼物
CCMenuItemImage* menuGifts = CCMenuItemImage::create("menu_gifts_n.png", "menu_gifts_s.png", this,
menu_selector(MessageView::menuGiftsClickCallback)) ;
// menuBack->setContentSize(CCSizeMake(67, 68)) ;
menuGifts->setAnchorPoint(ccp(0, 0.5)) ;
menuGifts->setPosition(ccp(0, topBar_height/2)) ;
//menuGifts->setPosition(ccp(right_width-2*item_width, topBar_height/2)) ;
//rightMenu->addChild(menuGifts) ;
// 返回大厅
CCMenuItemImage* menuBack = CCMenuItemImage::create("menu_back_n.png", "menu_back_s.png", this,
menu_selector(MessageView::menuBackClickCallback)) ;
menuBack->setAnchorPoint(ccp(0, 0.5)) ;
menuBack->setPosition(ccp(2*(item_width+10), topBar_height/2)) ;
//menuBack->setPosition(ccp(right_width, topBar_height/2)) ;
//rightMenu->addChild(menuBack) ;
//.........这里部分代码省略.........