本文整理汇总了C++中LabelTTF::setHorizontalAlignment方法的典型用法代码示例。如果您正苦于以下问题:C++ LabelTTF::setHorizontalAlignment方法的具体用法?C++ LabelTTF::setHorizontalAlignment怎么用?C++ LabelTTF::setHorizontalAlignment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LabelTTF
的用法示例。
在下文中一共展示了LabelTTF::setHorizontalAlignment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEnter
void DialogLayer::onEnter()
{
Layer::onEnter();
Size winSize = Director::getInstance()->getWinSize();
Point pCenter = Point(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(Size::ZERO)) {
getSpriteBackGround()->setPosition(winSize.width / 2, winSize.height / 2);
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(winSize.width / 2, winSize.height / 2);
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node*> vecArray = getMenuButton()->getChildren();
Ref* pObj = NULL;
int i = 0;
for(auto& e : vecArray){
Node* node = dynamic_cast<Node*>(e);
node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(i+1),winSize.height/2-contentSize.height/3));
i++;
}
// 显示对话框标题
if (getLabelTitle()){
getLabelTitle()->setPosition(pCenter + Vec2(0, contentSize.height / 2 - 30.0f));
this->addChild(getLabelTitle());
}
// 显示文本内容
if (getLabelContentText()){
LabelTTF* ltf = getLabelContentText();
ltf->setPosition(winSize.width / 2, winSize.height / 2 + 20);
//ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
this->addChild(ltf);
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.06, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0), NULL);
this->runAction(popupLayer);
}
示例2: onEnter
void PopLayer::onEnter()
{
Layer::onEnter();
Size winSize = Director::getInstance()->getVisibleSize();
Vec2 pCenter(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(Size::ZERO)) {
getSpriteBackGround()->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node *> array = getMenuButton()->getChildren();
getMenuButton()->alignItemsHorizontallyWithPadding(50);
getMenuButton()->setPosition(Vec2(winSize.width / 2, winSize.height / 2 - contentSize.height / 3));
// int i = 0;
// for(auto &bt: array)
// {
// Node* node = dynamic_cast<Node*>(bt);
// node->setPosition(Vec2( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
// i++;
// }
// 显示对话框标题
if (getLabelTitle()){
getLabelTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 35.0f)));
this->addChild(getLabelTitle());
}
if(getImgTitle())
{
getImgTitle()->setPosition((pCenter + Vec2(0, contentSize.height / 2 - 40.0f)));
this->addChild(getImgTitle());
}
// 显示文本内容
if (getLabelContentText()){
LabelTTF* ltf = getLabelContentText();
//ltf->setPosition(Vec2(winSize.width / 2, winSize.height / 2));
ltf->setPosition(pCenter);
ltf->setDimensions(Size(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(TextHAlignment::LEFT);
this->addChild(ltf);
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.06, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0), NULL);
this->runAction(popupLayer);
}
示例3: onEnter
void PopupLayer::onEnter()
{
Layer::onEnter();
//Size winSize = Director::getInstance()->getWinSize();
Point pCenter = ccp(winSize.width / 2, winSize.height / 2);
Size contentSize;
// 设定好参数,在运行时加载
if (getContentSize().equals(CCSizeZero))
{
getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(getSpriteBackGround(), 0, 0);
contentSize = getSpriteBackGround()->getTexture()->getContentSize();
} else {
Scale9Sprite *background = getSprite9BackGround();
background->setContentSize(getContentSize());
background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
this->addChild(background, 0, 0);
contentSize = getContentSize();
}
// 添加按钮,并设置其位置
this->addChild(getMenuButton());
float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
Vector<Node*> vecArray = getMenuButton()->getChildren();
int j=0;
for(auto it=vecArray.begin();it!=vecArray.end();it++)
{
Node* node = dynamic_cast<Node*>(*it);
node->setPosition(Point(winSize.width/2 - contentSize.width/2+btnWidth*(j+1),winSize.height/2-contentSize.height/3));
j++;
}
// 显示对话框标题
if (getLabelTitle())
{
getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 -20)));
getLabelTitle()->setColor(ccc3(0,0,0));
this->addChild(getLabelTitle());
}
switch(pop_type)
{
case LOTTERY:
{
setLotteryContext(contentSize);
break;
}
case LOTTERY_PUBLISH:
{
setPublishLotteryContext(contentSize);
break;
}
case LOADGAME:
{
setLoadGameContext(contentSize);
break;
}
default:
{
// 显示文本内容
if (getLabelContentText())
{
LabelTTF* ltf = getLabelContentText();
ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
ltf->setColor(ccc3(0,0,0));
this->addChild(ltf);
}
}
}
// 弹出效果
Action* popupLayer = Sequence::create(ScaleTo::create(0.0, 0.0),
ScaleTo::create(0.15, 1.05),
ScaleTo::create(0.08, 0.95),
ScaleTo::create(0.08, 1.0),
NULL);
this->runAction(popupLayer);
}