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


C++ LabelTTF::getContentSize方法代码示例

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


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

示例1: 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

示例2: handleTextRenderer

void RichText::handleTextRenderer(const char *text, const char *fontName, float fontSize, const Color3B &color, GLubyte opacity)
{
    LabelTTF* textRenderer = LabelTTF::create(text, fontName, fontSize);
    float textRendererWidth = textRenderer->getContentSize().width;
    _leftSpaceWidth -= textRendererWidth;
    if (_leftSpaceWidth < 0.0f)
    {
        float overstepPercent = (-_leftSpaceWidth) / textRendererWidth;
        std::string curText = text;
        int stringLength = curText.length();
        int leftLength = stringLength * (1.0f - overstepPercent);
        std::string leftWords = curText.substr(0, leftLength);
        std::string cutWords = curText.substr(leftLength, curText.length()-1);
        if (leftLength > 0)
        {
            LabelTTF* leftRenderer = LabelTTF::create(leftWords.substr(0, leftLength).c_str(), fontName, fontSize);
            leftRenderer->setColor(color);
            leftRenderer->setOpacity(opacity);
            pushToContainer(leftRenderer);
        }

        addNewLine();
        handleTextRenderer(cutWords.c_str(), fontName, fontSize, color, opacity);
    }
    else
    {
        textRenderer->setColor(color);
        textRenderer->setOpacity(opacity);
        pushToContainer(textRenderer);
    }
}
开发者ID:stephenw310,项目名称:gamedemo,代码行数:31,代码来源:UIRichText.cpp

示例3: 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();
    Point origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(PointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    Sprite* pSprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    return true;
}
开发者ID:Ben-Cortina,项目名称:GameBox,代码行数:58,代码来源:HelloWorldScene.cpp

示例4: 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();
    Point origin = Director::getInstance()->getVisibleOrigin();

    LabelTTF* pLabel = LabelTTF::create("Hello Girl", FONT_NAME, TITLE_FONT_SIZE);

	// position the label on the center of the screen
    pLabel->setPosition(Point(origin.x + visibleSize.width / 2,
		origin.y + visibleSize.height - pLabel->getContentSize().height));

	// add the label as a child to this layer
	this->addChild(pLabel, 1);

	return true;
}
开发者ID:sergey-shambir,项目名称:cocos2d-x_2_0_4_templete_for_qtcreator,代码行数:24,代码来源:HelloWorldScene.cpp

示例5: gameOver

void GamePlay::gameOver(float dt) {
//	Director::getInstance()->pause();
	gameState = End;
//invisible frame ready
	if (frameReady != NULL) {
		for (int i = 0; i < SUM_NUM; i++)
			frameReady[i]->setVisible(false);
	}

	boardWin = Sprite::create("board.png");
	boardWin->setPosition(Vec2(-visibleSize.width / 4, visibleSize.height / 2));
	boardWin->setZOrder(30);
	this->addChild(boardWin);
	float haflHeight = boardWin->getContentSize().height / 2;
	float haflWidth = boardWin->getContentSize().width / 2;

	auto jumpto = JumpTo::create(0.5,
			Vec2(visibleSize.width / 2, visibleSize.height / 2 - 3 * PADDING),
			PADDING * 3, 4);
	boardWin->runAction(jumpto);

	updatehightestRecord();

	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/music_win.ogg");
//congratulation
	Sprite* congratulation = Sprite::create("congratulation.png");
	congratulation->setPosition(
			Vec2(haflWidth,
					haflHeight * 2 - 3 * PADDING
							- congratulation->getContentSize().height));
	congratulation->setZOrder(40);
	boardWin->addChild(congratulation);

//highscore
	Sprite* newhighscore = Sprite::create("newhighscore.png");
	newhighscore->setPosition(
			Vec2(haflWidth,
					congratulation->getPositionY()
							- congratulation->getContentSize().height / 2
							- newhighscore->getContentSize().height / 2
							- 2 * PADDING));
	newhighscore->setZOrder(40);
	boardWin->addChild(newhighscore);

	//TODO
	if (timeplay > 0)
		NativeUtils::submitScore(
				getLeaderBoard(GamePlay::instance()->getLevel()),
				timeplay * 1000);
	if (timeplay > highScore) {
		newhighscore->setVisible(false);
	} else {
		newhighscore->setVisible(true);
	}

//gameover text
	Sprite* gameovertext = Sprite::create("gameovertext.png");
	gameovertext->setPosition(
			Vec2(4 * PADDING + gameovertext->getContentSize().width / 2,
					newhighscore->getPositionY()
							- newhighscore->getContentSize().height / 2
							- gameovertext->getContentSize().height / 2
							- 2 * PADDING));
	gameovertext->setZOrder(40);
	boardWin->addChild(gameovertext);

	float sizewidth = gameovertext->getContentSize().width;
	float sizeheight = gameovertext->getContentSize().height;
//show score
	LabelTTF *currentscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf",
			40);
	currentscore->setZOrder(50);
	currentscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(currentscore, timeplay);
	currentscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	currentscore->setPositionY(sizeheight / 2);
	gameovertext->addChild(currentscore);

	LabelTTF *highscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40);
	highscore->setZOrder(50);
	highscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(highscore, highScore);
	highscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	highscore->setPositionY(highscore->getContentSize().height / 2);
	gameovertext->addChild(highscore);

	std::string miniModeSprite = getLevelString(
			GamePlay::instance()->getLevel());
	Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png");
	miniMode->setPosition(
			Vec2(
					haflWidth * 2 - miniMode->getContentSize().width / 2
							- 3 * PADDING,
					gameovertext->getPositionY()
							+ miniMode->getContentSize().height / 2
							+ 2 * PADDING));
//.........这里部分代码省略.........
开发者ID:reddevil138,项目名称:NineGaps,代码行数:101,代码来源:GamePlay.cpp

示例6: init

bool GamePlay::init() {
	if (!Layer::init()) {
		return false;
	}

	gameState = Ready;
	visibleSize = Director::getInstance()->getVisibleSize();
	getSoundMusic();

	//load game AI
	//init array number and computation
	int ARRAY_NUMBER[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	arrNum = gameAI->randomNumber(ARRAY_NUMBER, SUM_NUM);
	for (int i = 0; i < SUM_NUM; i++) {
		arrNUM[i] = arrNum[i];
	}
	char s[SUM_COM] = "";
	//TODO change level
//	arrCOM = gameAI->randomComputation(s, SUM_COM,
//			GamePlay::instance()->getLevel() >= 2 ? 2 : 3);
	arrCOM = gameAI->randomComputation(s, SUM_COM, 2);
	for (int i = 0; i < SUM_COM; i++) {
		arrCOMPUTATE[i] = arrCOM[i];
	}
	for (int i = 0; i < SUM_COM / 2; i++) {
		tempResult[i] = INIT_FRAME;
	}

	int arr[GamePlay::instance()->getLevel()];
	int* arrayLevel = gameAI->randomLessNumber(arr,
			GamePlay::instance()->getLevel());

	//load background
	auto bg = Sprite::create("background.png");
	bg->setAnchorPoint(Vec2(0, 0));
	bg->setPosition(Vec2(0, 0));
	this->addChild(bg, -1);
	float rX = visibleSize.width / bg->getContentSize().width;
	float rY = visibleSize.height / bg->getContentSize().height;
	bg->setScaleX(rX);
	bg->setScaleY(rY);

	//show logo game
	Sprite *logoGame = Sprite::create("smalllogo.png");
	logoGame->setAnchorPoint(Vec2(0.0, 1.0));
	logoGame->setPosition(Vec2(PADDING, visibleSize.height - PADDING));
	logoGame->setTag(TAG_LOGO);
	logoGame->setScale(0.6f);
	this->addChild(logoGame);

	//load frame ready
	float baseY = logoGame->getPositionY()
			- logoGame->getBoundingBox().size.height - PADDING;
	float baseX = PADDING / 2;
	for (int i = 0; i < SUM_NUM; i++) {
		frameReady[i] = Sprite::create("frame.png");
		float width = frameReady[i]->getContentSize().width;
		float height = frameReady[i]->getContentSize().height;
		frameReady[i]->setTag(TAG_START_READY_POINT + i);
		frameReady[i]->setPositionX(baseX + 5.0 / 8.0 * i * width + width / 2);
		if (i % 2 == 0) {
			frameReady[i]->setPositionY(baseY - height / 2);
		} else {
			frameReady[i]->setPositionY(baseY - height);
		}
		this->addChild(frameReady[i]);
	}

	//create frame play
	float paddingY = 0;
	float paddingX = 0;
	for (int i = 0; i < SUM_NUM; i++) {
		float baseX = PADDING;
		framePlay[i] = TouchSprite::create("frame.png");
		framePlay[i]->setTag(TAG_FRAME_PLAY + i);
		paddingX = (visibleSize.width - PADDING * 4
				- framePlay[i]->getContentSize().width) / 3.0;
		framePlay[i]->setPositionX(
				PADDING + framePlay[i]->getContentSize().width / 2
						+ paddingX * (i % 3));

		float baseY = frameReady[0]->getPositionY();
		if (i % 3 == 0)
			paddingY = paddingX * ((int) i / 3 + 1);
		framePlay[i]->setPositionY(baseY - paddingY);
		framePlay[i]->score = 0;
		framePlay[i]->isFixed = false;
		for (int j = 0; j < GamePlay::instance()->getLevel(); j++) {
			if (arrNum[i] == arrayLevel[j]) {
				framePlay[i]->score = arrNum[i];
				//TODO
				framePlay[i]->isFixed = true;
				framePlay[i]->setDisplayFrame(
						SpriteFrame::create(
								"frame" + std::to_string(arrNum[i]) + ".png",
								framePlay[i]->getTextureRect()));
			}
		}
//		CCLog("frameplay[%d] = %d", i, framePlay[i]->score);
		this->addChild(framePlay[i]);
//.........这里部分代码省略.........
开发者ID:reddevil138,项目名称:NineGaps,代码行数:101,代码来源:GamePlay.cpp

示例7:

FailScene::FailScene(void)
{
	Vec2 points[] = {	Vec2(0, 0), 
						Vec2(0, 140),
						Vec2(400, 140),
						Vec2(400, 0) };
	DrawNode* draw = DrawNode::create();
	//±³¾°
	draw->drawPolygon(points, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw);
	draw->setAnchorPoint(Point(.5, .5));
	draw->setPositionX(ScreenUtil::getCenter().x - 200);
	draw->setPositionY(ScreenUtil::getCenter().y - 140);

	Vec2 points2[] = {	Vec2(0, 0), 
						Vec2(0, 150),
						Vec2(230, 150),
						Vec2(230, 0) };
	DrawNode* draw2 = DrawNode::create();
	//±³¾°
	draw2->drawPolygon(points2, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw2);
	draw2->setAnchorPoint(Point(.5, .5));
	draw2->setPositionX(ScreenUtil::getCenter().x - 115);
	draw2->setPositionY(ScreenUtil::getCenter().y + 40);

	LabelTTF* scoreTxt = LabelTTF::create("Score:", "Arial", 45);
	scoreTxt->setAnchorPoint(Point(0, .5));
	scoreTxt->setPosition(Point(draw2->getPositionX() + 10, 
								draw2->getPositionY() + 110));
	this->addChild(scoreTxt);

	LabelTTF* bestScoreTxt = LabelTTF::create("Best:", "Arial", 45);
	bestScoreTxt->setAnchorPoint(Point(0, .5));
	bestScoreTxt->setPosition(Point(scoreTxt->getPositionX(), 
									draw2->getPositionY() + 50));
	this->addChild(bestScoreTxt);

	LabelTTF* scoreValTxt = LabelTTF::create("0", "Arial", 45);
	scoreValTxt->setPositionX(scoreTxt->getPositionX() + scoreTxt->getContentSize().width + 25);
	scoreValTxt->setPositionY(scoreTxt->getPositionY());
	scoreValTxt->setTag(scoreValTxtTag);
	this->addChild(scoreValTxt);

	LabelTTF* bestScoreValTxt = LabelTTF::create("0", "Arial", 45);
	bestScoreValTxt->setPositionX(scoreValTxt->getPositionX());
	bestScoreValTxt->setPositionY(bestScoreTxt->getPositionY());
	bestScoreValTxt->setTag(bestScoreValTxtTag);
	this->addChild(bestScoreValTxt);

	LabelTTF* replayTxt = LabelTTF::create("Replay", "Arial", 45);
	MenuItemLabel* replayBtn = MenuItemLabel::create(replayTxt);
	replayBtn->setTag(replayBtnTag);

	LabelTTF* shareTxt = LabelTTF::create("Share", "Arial", 45);
	MenuItemLabel* shareBtn = MenuItemLabel::create(shareTxt);

	Menu* menu = Menu::create(replayBtn, shareBtn,  NULL);
	menu->setPositionX(ScreenUtil::getCenter().x);
	menu->setPositionY(ScreenUtil::getCenter().y - 70);
	menu->alignItemsHorizontallyWithPadding(50);
	menu->setTag(menuTag);
	this->addChild(menu);
}
开发者ID:kanon1109,项目名称:RotationBrid,代码行数:68,代码来源:FailScene.cpp

示例8: addChild

SocketIOTestLayer::SocketIOTestLayer(void)
	: _sioClient(NULL)
	, _sioEndpoint(NULL)
{
	//set the clients to NULL until we are ready to connect

	Size winSize = Director::getInstance()->getWinSize();
    
    const int MARGIN = 40;
    const int SPACE = 35;
    
    LabelTTF *label = LabelTTF::create("SocketIO Extension Test", "Arial", 28);
    label->setPosition(Point(winSize.width / 2, winSize.height - MARGIN));
    addChild(label, 0);
    	
    Menu *menuRequest = Menu::create();
    menuRequest->setPosition(Point::ZERO);
    addChild(menuRequest);
    
    // Test to create basic client in the default namespace
    LabelTTF *labelSIOClient = LabelTTF::create("Open SocketIO Client", "Arial", 22);
    MenuItemLabel *itemSIOClient = MenuItemLabel::create(labelSIOClient, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOClientClicked, this));
	itemSIOClient->setPosition(Point(VisibleRect::left().x + labelSIOClient->getContentSize().width / 2 + 5, winSize.height - MARGIN - SPACE));
    menuRequest->addChild(itemSIOClient);

	// Test to create a client at the endpoint '/testpoint'
    LabelTTF *labelSIOEndpoint = LabelTTF::create("Open SocketIO Endpoint", "Arial", 22);
    MenuItemLabel *itemSIOEndpoint = MenuItemLabel::create(labelSIOEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuSIOEndpointClicked, this));
	itemSIOEndpoint->setPosition(Point(VisibleRect::right().x - labelSIOEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - SPACE));
    menuRequest->addChild(itemSIOEndpoint);

	// Test sending message to default namespace
    LabelTTF *labelTestMessage = LabelTTF::create("Send Test Message", "Arial", 22);
    MenuItemLabel *itemTestMessage = MenuItemLabel::create(labelTestMessage, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageClicked, this));
    itemTestMessage->setPosition(Point(VisibleRect::left().x + labelTestMessage->getContentSize().width / 2 + 5, winSize.height - MARGIN - 2 * SPACE));
    menuRequest->addChild(itemTestMessage);

	// Test sending message to the endpoint '/testpoint'
    LabelTTF *labelTestMessageEndpoint = LabelTTF::create("Test Endpoint Message", "Arial", 22);
    MenuItemLabel *itemTestMessageEndpoint = MenuItemLabel::create(labelTestMessageEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestMessageEndpointClicked, this));
    itemTestMessageEndpoint->setPosition(Point(VisibleRect::right().x - labelTestMessageEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 2 * SPACE));
    menuRequest->addChild(itemTestMessageEndpoint);

	// Test sending event 'echotest' to default namespace
    LabelTTF *labelTestEvent = LabelTTF::create("Send Test Event", "Arial", 22);
    MenuItemLabel *itemTestEvent = MenuItemLabel::create(labelTestEvent, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventClicked, this));
    itemTestEvent->setPosition(Point(VisibleRect::left().x + labelTestEvent->getContentSize().width / 2 + 5, winSize.height - MARGIN - 3 * SPACE));
    menuRequest->addChild(itemTestEvent);

	// Test sending event 'echotest' to the endpoint '/testpoint'
    LabelTTF *labelTestEventEndpoint = LabelTTF::create("Test Endpoint Event", "Arial", 22);
    MenuItemLabel *itemTestEventEndpoint = MenuItemLabel::create(labelTestEventEndpoint, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEventEndpointClicked, this));
    itemTestEventEndpoint->setPosition(Point(VisibleRect::right().x - labelTestEventEndpoint->getContentSize().width / 2 - 5, winSize.height - MARGIN - 3 * SPACE));
    menuRequest->addChild(itemTestEventEndpoint);

	// Test disconnecting basic client
    LabelTTF *labelTestClientDisconnect = LabelTTF::create("Disconnect Socket", "Arial", 22);
    MenuItemLabel *itemClientDisconnect = MenuItemLabel::create(labelTestClientDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestClientDisconnectClicked, this));
    itemClientDisconnect->setPosition(Point(VisibleRect::left().x + labelTestClientDisconnect->getContentSize().width / 2 + 5, winSize.height - MARGIN - 4 * SPACE));
    menuRequest->addChild(itemClientDisconnect);

	// Test disconnecting the endpoint '/testpoint'
    LabelTTF *labelTestEndpointDisconnect = LabelTTF::create("Disconnect Endpoint", "Arial", 22);
    MenuItemLabel *itemTestEndpointDisconnect = MenuItemLabel::create(labelTestEndpointDisconnect, CC_CALLBACK_1(SocketIOTestLayer::onMenuTestEndpointDisconnectClicked, this));
    itemTestEndpointDisconnect->setPosition(Point(VisibleRect::right().x - labelTestEndpointDisconnect->getContentSize().width / 2 - 5, winSize.height - MARGIN - 4 * SPACE));
    menuRequest->addChild(itemTestEndpointDisconnect);
    
	// Sahred Status Label
    _sioClientStatus = LabelTTF::create("Not connected...", "Arial", 14, Size(320, 100), Label::HAlignment::LEFT);
    _sioClientStatus->setAnchorPoint(Point(0, 0));
    _sioClientStatus->setPosition(Point(VisibleRect::left().x, VisibleRect::rightBottom().y));
    this->addChild(_sioClientStatus);

	// Back Menu
    MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SocketIOTestLayer::toExtensionsMainLayer, this));
    itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
    Menu *menuBack = Menu::create(itemBack, NULL);
    menuBack->setPosition(Point::ZERO);
    addChild(menuBack);

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

示例9: 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();
    Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *closeItem = MenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        CC_CALLBACK_1(HelloWorld::menuCloseCallback,this));
    
	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(closeItem, NULL);
    pMenu->setPosition(Point::ZERO);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE);
    
    // position the label on the center of the screen
    pLabel->setPosition(Point(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    Sprite* pSprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);

	// initialize flash
    tinyswf::SWF::initialize(CCFlashLoadAsset, 256*1024); // 256kB buffer for libtess2
	tinyswf::Renderer::setInstance(new CCFlashRenderer);
	tinyswf::FontHandler::setInstance(new CCFlashFontHandler);
    CCFlash* pFlash = CCFlash::create("test.swf");
	pFlash->scheduleUpdate();
	this->addChild(pFlash,1);

	pFlash->getSWF()->get<tinyswf::Text>("_text")->setString(
		"<p>test<font color='#ff0000'>1234</font>hello world</p><p>font <font color='#00ffff'>color</font> test</p>");

#ifdef USE_HTTP
	CCHttpRequest* request = new CCHttpRequest();
	request->setUrl("https://localhost/codeigniter/user/login");
	request->setRequestType(CCHttpRequest::kHttpPost);
	request->setResponseCallback(this, httpresponse_selector(HelloWorld::onHttpRequestCompleted));
	request->setTag("POST login");

	std::string uuid;
	getUUID(uuid);
	std::string post = "uuid="+uuid;
	request->setRequestData(post.c_str(), post.length()); 

	CCHttpClient::getInstance()->send(request);
	request->release();
#endif
    return true;
}
开发者ID:Creativegame,项目名称:tinyswf,代码行数:83,代码来源:HelloWorldScene.cpp


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