本文整理汇总了C++中LabelTTF::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ LabelTTF::setPosition方法的具体用法?C++ LabelTTF::setPosition怎么用?C++ LabelTTF::setPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LabelTTF
的用法示例。
在下文中一共展示了LabelTTF::setPosition方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onEnter
void BaseTest::onEnter()
{
Layer::onEnter();
// add title and subtitle
std::string str = title();
const char * pTitle = str.c_str();
LabelTTF* label = LabelTTF::create(pTitle, "Arial", 32);
addChild(label, 9999);
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
LabelTTF* l = LabelTTF::create(strSubtitle.c_str(), "Thonburi", 16);
addChild(l, 9999);
l->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
// add menu
// CC_CALLBACK_1 == std::bind( function_ptr, instance, std::placeholders::_1, ...)
MenuItemImage *item1 = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(BaseTest::backCallback, this) );
MenuItemImage *item2 = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(BaseTest::restartCallback, this) );
MenuItemImage *item3 = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(BaseTest::nextCallback, this) );
Menu *menu = Menu::create(item1, item2, item3, NULL);
menu->setPosition(Point::ZERO);
item1->setPosition(Point(VisibleRect::center().x - item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
item2->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y+item2->getContentSize().height/2));
item3->setPosition(Point(VisibleRect::center().x + item2->getContentSize().width*2, VisibleRect::bottom().y+item2->getContentSize().height/2));
addChild(menu, 9999);
}
示例2: createRow
Node* TopRankScene::createRow(int rank, int score, std::string name){
Node* row = Node::create();
Size visibleSize = Director::getInstance()->getVisibleSize();
char _rank[2];
itoa(rank, _rank, 10);
LabelTTF* labelRank = LabelTTF::create(_rank, "AppleGothic", 20);
char _score[10];
itoa(score, _score, 10);
LabelTTF* labelScore = LabelTTF::create(_score, "AppleGothic", 20);
LabelTTF* labelName = LabelTTF::create(name, "AppleGothic", 20);
labelRank->setAnchorPoint(Point(0, 0));
labelRank->setPosition(visibleSize.width / 4 + 10, visibleSize.height / 20 * (5 - rank) + 10);
labelScore->setAnchorPoint(Point(0, 0));
labelScore->setPosition(visibleSize.width / 4 * 3 + 10, visibleSize.height / 20 * (5 - rank) + 10);
labelName->setAnchorPoint(Point(0, 0));
labelName->setPosition(visibleSize.width / 4 * 2 + 10, visibleSize.height / 20 * (5 - rank) + 10);
row->addChild(labelName);
row->addChild(labelRank);
row->addChild(labelScore);
row->setAnchorPoint(Point(0, 0));
row->setPosition(0, visibleSize.height / 20 * (5 - rank));
return row;
}
示例3: createFirstRow
Node* TopRankScene::createFirstRow(){
Node* row = Node::create();
Size visibleSize = Director::getInstance()->getVisibleSize();
LabelTTF* labelRank = LabelTTF::create("排名", "AppleGothic", 20);
LabelTTF* labelScore = LabelTTF::create("分数", "AppleGothic", 20);
LabelTTF* labelName = LabelTTF::create("姓名", "AppleGothic", 20);
labelRank->setAnchorPoint(Point(0, 0));
labelRank->setPosition(visibleSize.width / 4, visibleSize.height / 20 * 5 + 10);
labelScore->setAnchorPoint(Point(0, 0));
labelScore->setPosition(visibleSize.width / 4 * 3 + 10, visibleSize.height / 20 * 5 + 10);
labelName->setAnchorPoint(Point(0, 0));
labelName->setPosition(visibleSize.width / 4 * 2 + 10, visibleSize.height / 20 * 5 + 10);
row->addChild(labelName);
row->addChild(labelRank);
row->addChild(labelScore);
row->setAnchorPoint(Point(0, 0));
row->setPosition(0, visibleSize.height / 20 * 5+ 10);
return row;
}
示例4: init
bool ResultLayer::init()
{
if (!Layer::init())
{
return false;
}
//des
LabelTTF* labelDes = LabelTTF::create(PlayRound::shared()->getPrivityDescription(PlayRound::shared()->getLevel()), "黑体", FONTSIZE(25));
//LabelTTF* labelDes = LabelTTF::create(PlayRound::shared()->getPrivityDescription(0), "黑体", 30);
labelDes->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.9));
addChild(labelDes);
__String* strLevel = __String::createWithFormat("我到了第%d层啦!",PlayRound::shared()->getLevel());
LabelTTF* labelLevel = LabelTTF::create(strLevel->getCString(), "黑体", FONTSIZE(40));
labelLevel->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.8));
addChild(labelLevel);
Sprite* spNormal = Sprite::create("image/btn_restart.png");
Sprite* spSelect = Sprite::create("image/btn_restart.png");
// spNormal->setScale(960/COMWinSize().height);
// spSelect->setScale(960/COMWinSize().height);
spSelect->setColor(Color3B(200,200,200));
MenuItemSprite* itemSp = MenuItemSprite::create(spNormal, spSelect, CC_CALLBACK_1(ResultLayer::onClick, this));
//MenuItemLabel* label = MenuItemLabel::create(LabelTTF::create("重新开始", "黑体", 50),CC_CALLBACK_1(ResultLayer::onClick, this) );
itemSp->setTag(kResultRestartTag);
Menu* menu = Menu::create(itemSp, nullptr);
menu->setPosition(Point(COMWinSize().width/2,COMWinSize().height/2));
this->addChild(menu);
if (CCRANDOM_0_1()>0.8)
{
ShowYouAd::shared()->showYouWallSpot();
}
//Results.m4a
CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("Sound/Results.m4a");
//历史分数
__String* strHistory;
int iHistory = UserDefault::getInstance()->getIntegerForKey("HistoryScore");
if (iHistory<PlayRound::shared()->getLevel()) {
iHistory = PlayRound::shared()->getLevel();
UserDefault::getInstance()->setIntegerForKey("HistoryScore", PlayRound::shared()->getLevel());
UserDefault::getInstance()->flush();
strHistory = __String::createWithFormat("打破记录啦:%d层!!!",iHistory);
}
else
{
strHistory = __String::createWithFormat("历史最高:%d层",iHistory);
}
LabelTTF* ttfHistory = LabelTTF::create(strHistory->getCString(), "黑体", FONTSIZE(50));
ttfHistory->setPosition(Point(COMWinSize().width/2,COMWinSize().height*0.7));
addChild(ttfHistory);
return true;
}
示例5: setChatVector
void ChatLayer::setChatVector(std::vector<std::string> textVector ,
std::vector<std::string> senderNameVector,std::vector<int> senderId) {
std::reverse(textVector.begin(), textVector.end());
std::reverse(senderNameVector.begin(), senderNameVector.end());
std::reverse(senderId.begin(), senderId.end());
this->textVector = textVector;
this->senderNameVector = senderNameVector;
this->senderId = senderId;
int i = 0;
CCLOG("__________ Message __________");
for (std::vector<std::string>::iterator it = this->textVector.begin() ; it != this->textVector.end(); ++it) {
std::string message;
LabelTTF* searchLabel = NULL;
int count = 0;
if (this->senderId.at(i) == UserDefault::getInstance()->getIntegerForKey("Player_ID")) {
message = "Me: " + this->textVector.at(i);
count = (message.length()/CHARACTER_IN_LINE)+1;
searchLabel = LabelTTF::create(message.c_str(), "helvetica", 24,Size(275,LINE_HEIGHT*count), TextHAlignment::LEFT,TextVAlignment::TOP);
searchLabel->setAnchorPoint(Point(0,1));
searchLabel->setPosition(10,700 - (numberOfLines * LINE_HEIGHT) - (numberOfMessages * LINE_HEIGHT/2));
}
else {
message = this->senderNameVector.at(i) + ": "+ this->textVector.at(i);
count = (message.length()/CHARACTER_IN_LINE)+1;
searchLabel = LabelTTF::create(message.c_str(), "helvetica", 24,Size(275,LINE_HEIGHT*count), TextHAlignment::LEFT,TextVAlignment::TOP);
searchLabel->setAnchorPoint(Point(0,1));
searchLabel->setPosition(10,700 - (numberOfLines * LINE_HEIGHT) - (numberOfMessages * LINE_HEIGHT/2));
}
searchLabel->setColor(Color3B(255, 0, 0));
chatNode->addChild(searchLabel);
numberOfLines = numberOfLines + count;
numberOfMessages = numberOfMessages + 1;
CCLOG("Count :: %d Message :: %s",count,message.c_str());
i++;
}
stopWaitingAnim();
}
示例6: initWithWon
bool GameOverScene::initWithWon(int won){
if (!LayerColor::initWithColor(cocos2d::Color4B(255,255,255,255))) {
return false;
}
LabelTTF *label = nullptr;
char *message;
if (won) {
label = LabelTTF::create("You Win\nHappy Birthday, Stephen!", "Arial", 33);
}else{
label = LabelTTF::create("You Lose\nHappy Birthday, Stephen!", "Arial", 33);
}
Size winSize = Director::getInstance()->getWinSize();
label->setColor(Color3B(0, 0, 0));
label->setPosition(Point(winSize.width/2, winSize.height/2));
this->addChild(label);
message = NULL;
this->runAction(
Sequence::create(DelayTime::create(5)
,CallFunc::create(
[](){
//gameOverDone
Director::getInstance()->replaceScene(HelloWorld::createScene());
})
, NULL));
return true;
}
示例7: updateLayerMessageBox
void AssetsUpdateLayer::updateLayerMessageBox()
{
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ccb/ccbResources/SystemLoading.plist");
CCLayer* layer = CCLayer::create();
layer->ignoreAnchorPointForPosition(false);
layer->setContentSize(Size(960, 640));
layer->setPosition(Point(Director::getInstance()->getWinSize().width * 0.5, Director::getInstance()->getWinSize().height * 0.5));
layer->setScale(Director::getInstance()->getWinSize().width / 960);
addChild(layer, 1);
Sprite* messageboxSprite = Sprite::createWithSpriteFrameName("set_floor_v1.png");
messageboxSprite->setPosition(Point(480, 320));
layer->addChild(messageboxSprite, 1);
LabelTTF* labelContent = LabelTTF::create(Localization::getInstance()->getValueByKey("Loading_warning_need_update"), "Helvetica",32);
labelContent->setPosition(Point(480, 420));
layer->addChild(labelContent, 1);
ControlButton* btn = ControlButton::create(LabelTTF::create(Localization::getInstance()->getValueByKey("BUTTON_DONE"), "Helvetica", 32), Scale9Sprite::createWithSpriteFrameName("set_button2.png"));
btn->setPreferredSize(CCSize(191,70));
btn->setPosition(Point(480, 220));
btn->addTargetWithActionForControlEvents(this, cccontrol_selector(AssetsUpdateLayer::GoToAppPage), Control::EventType::TOUCH_UP_INSIDE);
layer->addChild(btn, 1);
}
示例8: onEnter
void PauseTest::onEnter()
{
//
// This test MUST be done in 'onEnter' and not on 'init'
// otherwise the paused action will be resumed at 'onEnter' time
//
ActionManagerTest::onEnter();
LabelTTF* l = LabelTTF::create("After 5 seconds grossini should move", "Thonburi", 16);
addChild(l);
l->setPosition( ccp(VisibleRect::center().x, VisibleRect::top().y-75) );
//
// Also, this test MUST be done, after [super onEnter]
//
Sprite* grossini = Sprite::create(s_pPathGrossini);
addChild(grossini, 0, kTagGrossini);
grossini->setPosition(VisibleRect::center() );
Action* action = MoveBy::create(1, ccp(150,0));
Director* pDirector = Director::sharedDirector();
pDirector->getActionManager()->addAction(action, grossini, true);
schedule( schedule_selector(PauseTest::unpause), 3);
}
示例9: init
bool GameOver::init()
{
Layer::init();
Size winSize = Director::getInstance()->getVisibleSize();
Sprite* bg = Sprite::createWithSpriteFrameName("background_2.png");
this->addChild(bg);
bg->setAnchorPoint(Point::ZERO);
Sprite* showScore = Sprite::create("[email protected]");
this->addChild(showScore);
showScore->setPosition(winSize.width/2 ,winSize.height/2 + 50);
int res = InGameLayer::getScore();
char chres[100];
sprintf(chres,"%d ",res);
LabelTTF* scorettf = LabelTTF::create(chres,"WRYH",48);
this->addChild(scorettf);
scorettf->setPosition(showScore->getPosition() - Point(0,50));
//退出游戏按钮
Sprite* closeSprite = Sprite::create("gameover.png");
MenuItemSprite *closed = MenuItemSprite::create(closeSprite,NULL,NULL,
CC_CALLBACK_1(GameOver::closeGame,this));
Menu* closeMenu = Menu::create(closed,NULL);
this->addChild(closeMenu);
closeMenu->setPosition(winSize.width*2/3,winSize.height/3);
//重新开始游戏按钮
Sprite* reStrart = Sprite::create("reStrart.png");
MenuItemSprite *reStrartSprite = MenuItemSprite::create(reStrart,NULL,NULL,
CC_CALLBACK_1(GameOver::reStrartGame,this));
Menu* reStrartMenu = Menu::create(reStrartSprite,NULL);
this->addChild(reStrartMenu);
reStrartMenu->setPosition(winSize.width/3,winSize.height/3);
return true;
}
示例10: aboutGameCallback
void HelloWorld::aboutGameCallback(Object* pSender)
{
Size size = Director::sharedDirector()->getWinSize();
//显示关于的内容
LabelTTF* label = LabelTTF::create("Made by LJW", "Arial", 30);
label->setPosition(Point(size.width / 2, size.height / 2));
Scene* s = Scene::create();
Layer* layer = Layer::create();
layer->addChild(label, 1);
//返回按钮
LabelTTF* pBackLabel = LabelTTF::create("Back", "Arial", 30);
MenuItemLabel* pBackItem = MenuItemLabel::create(pBackLabel, this, menu_selector(HelloWorld::backGameCallback));
Menu* pBackMenu = Menu::create(pBackItem, NULL);
pBackItem->setPosition(Point(size.width - 50, 50));
pBackMenu->setPosition(CCPointZero);
layer->addChild(pBackMenu, 1);
s->addChild(layer);
Director::sharedDirector()->replaceScene(s);
//s->release();
//layer->release();
}
示例11: standardButtonWithTitle
ControlButton* standardButtonWithTitle( const char * bgname, const char * bgseledname, const char * title){
//Creates and return a button with a default background and title color.
// Scale9Sprite *backgroundButton = Scale9Sprite::create(bgname);//按下前
// Scale9Sprite *backgroundHighlightedButton = Scale9Sprite::create(bgseledname);//按下后
ControlButton* btn = ControlButton::create();
btn->setPreferredSize(Size(522, 88));
Scale9Sprite* normal = Scale9Sprite::create(bgname);
Scale9Sprite* select = Scale9Sprite::create(bgseledname);
Scale9Sprite* hightlight = Scale9Sprite::create(bgseledname);
Scale9Sprite* disable = Scale9Sprite::create(bgname);
btn->setBackgroundSpriteForState(normal, Control::State::NORMAL);
btn->setBackgroundSpriteForState(select, Control::State::SELECTED);
btn->setBackgroundSpriteForState(hightlight, Control::State::HIGH_LIGHTED);
btn->setBackgroundSpriteForState(disable, Control::State::DISABLED);
LabelTTF *titleButton = LabelTTF::create(title, "AmericanTypewriter", 30);//添加文字
titleButton->setAnchorPoint(Point(0.5f, 0.5f));
titleButton->setPosition(Point(btn->getContentSize().width/2, btn->getContentSize().height/2));
titleButton->setColor(Color3B::BLACK);//设置文字点击前的颜色
titleButton->setTag(1000);
btn->addChild(titleButton);
return btn;
}
示例12: add_option
void MyListView::add_option(const char* name)
{
Sprite* option = Sprite::create("situ_item_background_normal.png");
option->setPosition(0,-options_vec.size()*option_height-option_height);
option->setCascadeOpacityEnabled(true);
option->setOpacity(0);
LabelTTF* label = LabelTTF::create(name,"Arial",50);
label->setFontFillColor(Color3B(249,222,144));
label->setPosition(option->getBoundingBox().size.width/2,option->getBoundingBox().size.height/2);
option->addChild(label);
this->addChild(option);
this->options_vec.pushBack(option);
if(options_vec.size()*option_height+option_height>height)
{
height = options_vec.size()*option_height+option_height;
}
}
示例13: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !Layer::init() )
{
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
Sprite *bg = Sprite::create("bg.jpg");
bg->setPosition(visibleSize/2);
addChild(bg);
LabelTTF *label = LabelTTF::create("Show Next Scene", "Coureir", 36);
addChild(label);
label->setPosition(visibleSize/2);
EventListenerTouchOneByOne *listener = EventListenerTouchOneByOne::create();
listener->onTouchBegan = [label](Touch *t,Event *e){
if (label->getBoundingBox().containsPoint(t->getLocation())) {
Director::getInstance()->replaceScene(TransitionPageTurn::create (1,ImageScene::createScene(),0));
};
return false;
};
Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, label);
return true;
}
示例14: initPropList
void LevelStartView::initPropList(cocos2d::Layer * pStart)
{
std::vector<std::string> propList;
getPropListData(propList);
size_t i = 0;
for (std::map<std::string, std::string>::iterator it = m_propList.begin(); it != m_propList.end(); ++it)
{
Sprite* pPropList = static_cast<Sprite *>(pStart->getChildByName(propList.at(i++)));
Size s = pPropList->getContentSize();
Sprite* pProp = Sprite::create(it->first);
pProp->setScale(1.2f);
pProp->setPosition(s.width / 2, s.height / 2);
pProp->setTag(i + 1);
pPropList->addChild(pProp);
LabelTTF* propFee = LabelTTF::create(it->second, "fonts/Marker Felt.ttf",36);
propFee->setFontFillColor(ccc3(126, 126, 126));
propFee->setPosition(s.width-20, -s.height/2+20);
pPropList->addChild(propFee);
auto listener = EventListenerTouchOneByOne::create();
listener->setSwallowTouches(true);
listener->onTouchBegan = CC_CALLBACK_2(LevelStartView::onTouchBegan, this);
listener->onTouchMoved = CC_CALLBACK_2(LevelStartView::onTouchMoved, this);
listener->onTouchEnded = CC_CALLBACK_2(LevelStartView::onTouchEnded, this);
this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, pProp);
}
}
示例15: init
void NetworkTestView::init(Scene* scene) {
_scene = scene;
Node* node = Node::create();
node->setPosition(LayoutUtils::visibleCenter() - Point(240, 160));
_scene->addChild(node, Z_ORDER_ROOT, TAG_ROOT);
// background
Point bgPos(240, 160);
float bgScale = 2.0f * ImageUtils::scale4OneSizeImage();
Sprite* bg = Sprite::create("bg.png");
bg->setScale(bgScale);
bg->setPosition(bgPos);
node->addChild(bg, INT_MIN);
// back button
Button* btnBack = WidgetUtils::createTTFButton("Back", "orange", [this]() {
emitSelectBack();
});
btnBack->setPosition(Point(430, 295));
node->addChild(btnBack, INT_MAX);
// get button
Button* btnGet = WidgetUtils::createTTFButton("Get", [this]() {
get();
});
btnGet->setPosition(Point(240, 295));
node->addChild(btnGet, Z_ORDER_BTN_GET);
// result label
LabelTTF* lblResult = LabelTTF::create("", "Helvetica", 16, Size(460, 250), TextHAlignment::LEFT, TextVAlignment::TOP);
lblResult->setPosition(Point(240, 135));
node->addChild(lblResult, Z_ORDER_RESULT, TAG_RESULT);
}