当前位置: 首页>>代码示例>>C++>>正文


C++ LabelTTF类代码示例

本文整理汇总了C++中LabelTTF的典型用法代码示例。如果您正苦于以下问题:C++ LabelTTF类的具体用法?C++ LabelTTF怎么用?C++ LabelTTF使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LabelTTF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: title

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);

}
开发者ID:CBanDa,项目名称:cocos2d-x-3.0alpha0-pre,代码行数:35,代码来源:BaseTest.cpp

示例2: sprintf

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;
}
开发者ID:picassoporker,项目名称:flyshot,代码行数:33,代码来源:GameOver.cpp

示例3: setTouchEnabled

void TestUseMutiplePicture::onEnter()
{
    ArmatureTestLayer::onEnter();
    setTouchEnabled(true);

    displayIndex = 0;

    armature = Armature::create("Knight_f/Knight");
    armature->getAnimation()->playByIndex(0);
    armature->setPosition(Point(VisibleRect::center().x, VisibleRect::left().y));
    armature->setScale(1.2f);
    addChild(armature);

    std::string weapon[] = {"weapon_f-sword.png", "weapon_f-sword2.png", "weapon_f-sword3.png", "weapon_f-sword4.png", "weapon_f-sword5.png", "weapon_f-knife.png", "weapon_f-hammer.png"};

    for (int i = 0; i < 7; i++)
    {
        Skin *skin = Skin::createWithSpriteFrameName(weapon[i].c_str());
        armature->getBone("weapon")->addDisplay(skin, i);
    }

    // 	CCSpriteDisplayData displayData;
    // 	for (int i = 0; i < 7; i++)
    // 	{
    // 		displayData.setParam(weapon[i].c_str());
    // 		armature->getBone("weapon")->addDisplay(&displayData, i);
    // 	}

    LabelTTF *l = LabelTTF::create("This is a weapon!", "Arial", 18);
    l->setAnchorPoint(Point(0.2f, 0.5f));
    armature->getBone("weapon")->addDisplay(l, 7);
}
开发者ID:csouls,项目名称:nyangame-v3,代码行数:32,代码来源:ArmatureScene.cpp

示例4: 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(); 
 
} 
开发者ID:ljwrx,项目名称:OurGame,代码行数:26,代码来源:HelloWorldScene.cpp

示例5: getPropListData

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);
	}
}
开发者ID:tinyCome,项目名称:Solitaire,代码行数:31,代码来源:LevelStartView.cpp

示例6: addChild

// 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;
}
开发者ID:syouotm,项目名称:Cocos2d-x_Lessons2,代码行数:33,代码来源:HelloWorldScene.cpp

示例7: setTouchEnabled

MainMenuLayer::MainMenuLayer()
{
	setTouchEnabled(true);
	// Font Item

	gdraw = new GLESDebugDraw();

	setTouchEnabled(true);
	setAccelerometerEnabled(true);


	MenuItemFont::setFontSize(40);
	MenuItemFont::setFontName("fonts/Courier New.ttf");


	MenuItemFont* item = MenuItemFont::create("Play", CC_CALLBACK_1(MainMenuLayer::menuCallback, this));
	MenuItemFont* item1 = MenuItemFont::create("Exit", CC_CALLBACK_1(MainMenuLayer::menuExitCallback, this));
	Menu* menu = Menu::create(item, item1, nullptr);
	addChild(menu, -1);
	menu->alignItemsVertically();
	menu->setPosition(screenWidth / 2, screenHeight / 2);


	LabelTTF *label = LabelTTF::create("Tilter 2D", "fonts/Marker Felt.ttf", 50);
	addChild(label, -1);
	label->setColor(Color3B(255, 0, 0));
	label->setPosition(Point(screenWidth / 2, screenHeight - 50));
}
开发者ID:smrutled,项目名称:Tilter2dx,代码行数:28,代码来源:MainMenuLayer.cpp

示例8: init

bool GameOver::init() {
  if(!Layer::init()){
    return false;
  }
  auto visibleSize = Director::getInstance()->getVisibleSize();
  auto origin = Director::getInstance()->getVisibleOrigin();
  LabelTTF* thanks = LabelTTF::create("Thanks for playing +Neuron", "Serif", 50);
  thanks->setPosition(Point(visibleSize.width/2, visibleSize.height - thanks->getContentSize().height*2));
  this->addChild(thanks);

  auto _nickname_input = new TextFieldTTFDefault();
  _nickname_input->autorelease();
  _nickname_input->onEditingEnd = CC_CALLBACK_1(GameOver::getNickName, this);
  this->addChild(_nickname_input);

  /*
   *Todo accion por fuera de INIT genera un fallo de segmentacion
   *??como hacer para aparecer el boton despues de escribir el nombre?
   * -intente con updateGame, fallo de segmentacion
   * -intente desde getNickname, fallo de segmentacion
   */
  /*
  auto endGameItem = MenuItemImage::create(
				 "botones/salir.png",
				 "botones/salir.png",
				 CC_CALLBACK_0(GameOver::closeAndSave, this)
				 );
  endGameItem->setPosition(Point(visibleSize.width - endGameItem->getContentSize().width + origin.x, visibleSize.height/5 + origin.y));
  endGameItem->runAction(Hide::create());
  auto menu = Menu::create(endGameItem, NULL);
  menu->setPosition(Point::ZERO);
  _nickname_input->addChild(menu);*/

  return true;
}
开发者ID:PICHURRIAJUEGOS-,项目名称:moreneuron,代码行数:35,代码来源:GameOverScene.cpp

示例9: 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); 
}
开发者ID:bassarisse,项目名称:LostInCaves,代码行数:28,代码来源:ActionManagerTest.cpp

示例10: 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;
}
开发者ID:jiangchao1987,项目名称:crazyvideo,代码行数:30,代码来源:Tools.cpp

示例11: sprintf

void TestAsynchronousLoading::onEnter()
{
    ArmatureTestLayer::onEnter();

    //CCLOG("armature version : %s", armatureVersion());

    backItem->setEnabled(false);
    restartItem->setEnabled(false);
    nextItem->setEnabled(false);

    char pszPercent[255];
    sprintf(pszPercent, "%s %f", subtitle().c_str(), 0.0f);
    LabelTTF *label = (LabelTTF *)getChildByTag(10001);
    label->setString(pszPercent);


    //! create a new thread to load data
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/knight.png", "armature/knight.plist", "armature/knight.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/robot.png", "armature/robot.plist", "armature/robot.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml", this, schedule_selector(TestAsynchronousLoading::dataLoaded));
    ArmatureDataManager::getInstance()->addArmatureFileInfoAsync("armature/Cowboy.ExportJson", this, schedule_selector(TestAsynchronousLoading::dataLoaded));

    //! load data directly
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/knight.png", "armature/knight.plist", "armature/knight.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/weapon.png", "armature/weapon.plist", "armature/weapon.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/robot.png", "armature/robot.plist", "armature/robot.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/cyborg.png", "armature/cyborg.plist", "armature/cyborg.xml");
    // 	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Dragon.png", "armature/Dragon.plist", "armature/Dragon.xml");
    //	ArmatureDataManager::getInstance()->addArmatureFileInfo("armature/Cowboy.ExportJson");

}
开发者ID:csouls,项目名称:nyangame-v3,代码行数:33,代码来源:ArmatureScene.cpp

示例12: init

// Initializes the GameOver
bool GameOver::init()
{
	if (!Layer::init()) {
		return false;
	}

	// Creates the GameOver text
	LabelTTF* gameOverText = LabelTTF::create("Game Over",
			String::createWithFormat("%s.ttf", FONT_MAIN)->getCString(), 50);
	gameOverText->setPosition(Point(DESIGN_WIDTH / 2, DESIGN_HEIGHT * .8));
	this->addChild(gameOverText, 1);

	// Creates the buttons for the menu
    auto replayButton = MenuItemImage::create("replay.png", "replay.png", CC_CALLBACK_0(GameOver::replay, this));
    auto menuButton = MenuItemImage::create("replay.png", "replay.png", CC_CALLBACK_0(GameOver::mainMenu, this));

    // Creates the menu and adds the buttons
    Menu* menu = Menu::create(replayButton, menuButton, NULL);
    menu->alignItemsVerticallyWithPadding(30);
    this->addChild(menu, 1);

    this->setVisible(false);

    return true;
}
开发者ID:jsurk,项目名称:OurGame,代码行数:26,代码来源:GameOver.cpp

示例13: 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;
	}
}
开发者ID:windswhisper,项目名称:cocos2d,代码行数:27,代码来源:StageLayer.cpp

示例14: Point

	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);
	}
开发者ID:shuidong,项目名称:coconut-sample,代码行数:34,代码来源:NetworkTestView.cpp

示例15:

LabelTTF *CCActionTest::createTestLabel(const std::string &name)
{
	LabelTTF *label = LabelTTF::create(name, "Arial", 20);
	label->setPosition(Point(200, 200));
	addChild(label);
	return label;
}
开发者ID:tklee1975,项目名称:ccx3-game,代码行数:7,代码来源:CCActionTest.cpp


注:本文中的LabelTTF类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。