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

}
Esempio n. 2
0
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("*****@*****.**");
	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;
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
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(); 
 
} 
Esempio n. 5
0
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);
	}
}
// 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;
}
Esempio n. 7
0
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));
}
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;
}
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); 
}
Esempio n. 10
0
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;
}
Esempio n. 11
0
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");

}
Esempio n. 12
0
// 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;
}
Esempio n. 13
0
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;
	}
}
Esempio n. 14
0
	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);
	}
Esempio n. 15
0
LabelTTF *CCActionTest::createTestLabel(const std::string &name)
{
	LabelTTF *label = LabelTTF::create(name, "Arial", 20);
	label->setPosition(Point(200, 200));
	addChild(label);
	return label;
}
Esempio n. 16
0
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;
}
Esempio n. 17
0
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);

}
Esempio n. 18
0
void Tutorial::msg2(float time)
{

	Node* pMsg = Sprite::create("help_msg2.png");
	pMsg->setPosition(Point(280, visibleSize.height * 0.80-150));
	pMsg->setTag(tagMsg);
	this->addChild(pMsg,2);

	Node* pYubi  = this->getChildByTag(tagYubi);
	pYubi->runAction(RotateBy::create(0.5f, -90.0f));

	pMsg = Sprite::create("help_msg3.png");
	pMsg->setPosition(Point(visibleSize.width/2 , origin.y + 200));
	pMsg->setTag(tagTap2);
	this->addChild(pMsg,2);

	LabelTTF* arrowLabel = LabelTTF::create("タップしてね", "Arial", 40);
	arrowLabel->setColor(ccc3(0, 0, 0));
	arrowLabel->setPosition(Point(visibleSize.width/2 , origin.y + 200));
	arrowLabel->setTag(tagTap);
	this->addChild(arrowLabel,3);
	arrowLabel->runAction(CCRepeatForever::create(Blink::create(5,7)));

	scene_flag++;

}
Esempio n. 19
0
bool CChooseLetterWindow::init()
{	   
	m_Back = Sprite::create("choose_letter.png");
	m_Back->setPosition(600,384); 
	m_Back->setVisible(false);
	addChild(m_Back);
	std::vector<char> m_Letters;
	m_Letters.resize(26);
	m_Letters[0] = 'a'; m_Letters[1] = 'b'; m_Letters[2] = 'c'; m_Letters[3] = 'd'; m_Letters[4] = 'e'; m_Letters[5] = 'f'; m_Letters[6] = 'g'; 
	m_Letters[7] = 'h'; m_Letters[8] = 'i'; m_Letters[9] = 'j'; m_Letters[10] = 'k'; m_Letters[11] = 'l'; m_Letters[12] = 'm'; m_Letters[13] = 'n'; 
	m_Letters[14] = 'o'; m_Letters[15] = 'p'; m_Letters[16] = 'q'; m_Letters[17] = 'r'; m_Letters[18] = 's'; m_Letters[19] = 't'; m_Letters[20] = 'u'; 
	m_Letters[21] = 'v'; m_Letters[22] = 'w'; m_Letters[23] = 'x'; m_Letters[24] = 'y'; m_Letters[25] = 'z'; 

	float startPosX = -460.0f;
	float startPosY = -150.0f;
	float stepX = 45.0f;
	float stepY = 45.0f;
	int columnCount = 6;
	int rowCount = 4;
	int id = 0;
	int currentColumn = 0;
	int currentRow = 0;
	m_pMenu = CCMenu::create();
	for(int i=0;i<m_Letters.size();i++)
	{
		Point pos = Point(startPosX+(currentColumn*stepX),startPosY+(-currentRow*stepY));
		CCMenuItem * button = CCMenuItemImage::create(
			"base.png",
			"fixed.png",
			this,
			menu_selector(CChooseLetterWindow::LetterBtnClick));
		button->setTag(int(m_Letters[i]));
		button->setScale(0.35f);
		button->setPosition(pos);
		LabelTTF * letterLabel = LabelTTF::create("0","helvetica",82);	
		letterLabel->setPosition(button->getContentSize().width/2,button->getContentSize().height/2);
		letterLabel->setColor(Color3B(0,0,0));
		std::string str = "A";
		str[0] = m_Letters[i];
		std::transform(str.begin(), str.end(),str.begin(), ::toupper);
		letterLabel->setString(str);
		button->addChild(letterLabel);
		//letterLabel->setPosition(pos);

		currentColumn++;
		if(currentColumn == columnCount)
		{
			currentColumn = 0;
			currentRow++;
		}
		m_pMenu->addChild(button);
		m_pMenu->setEnabled(false);
	}

	m_Back->addChild(m_pMenu);


	return true;
}
Esempio n. 20
0
void Game::showWin()
{
	LabelTTF *label = LabelTTF::create("GameWin!!", "Arial", 36.0f);
    
	Size s = Director::getInstance()->getWinSize();
	label->setPosition(s.width/2, s.height/2);
    this->addChild(label);
    this->scheduleOnce(schedule_selector(Game::exitGame), 2.0);
}
Esempio n. 21
0
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);
}
Esempio n. 22
0
// 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;
}
Esempio n. 23
0
void PopLayer::setContentText(const char* text, int fontsize /*= 20*/, int padding /*= 50*/, int paddingTop /*= 100*/)
{
    
    LabelTTF* ltf = LabelTTF::create(text, "", fontsize);
    //LabelTTF* ltf = LabelTTF::create("longggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg", "", fontsize);
    ltf->setColor(Color3B::WHITE);
    setLabelContentText(ltf);
    m_contentPadding = padding;
    m_contentPaddingTop = paddingTop;
}
Esempio n. 24
0
void FailScene::setScore( int score, int bestScore)
{
	String* str = String::createWithFormat("%d", score);
	LabelTTF* scoreValTxt = (LabelTTF* )this->getChildByTag(scoreValTxtTag);
	scoreValTxt->setString(str->_string);

	str = String::createWithFormat("%d", bestScore);
	LabelTTF* bestScoreValTxt = (LabelTTF* )this->getChildByTag(bestScoreValTxtTag);
	bestScoreValTxt->setString(str->_string);
}
Esempio n. 25
0
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;
}
Esempio n. 26
0
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;
}
Esempio n. 27
0
void Akuerdate::pintoPalabra(){
    
    LabelTTF *texto = CCLabelTTF::create(gProfesion->obtenerPalabraElemento(tagActual)->getCString(), "HVD_Comic_Serif_Pro.ttf",100,Size(panelPalabras->getContentSize().width-margenPanelPalabrasInterno,130), TextHAlignment::CENTER);
    texto->setColor(Color3B(228,70,106));
    texto->setVerticalAlignment(TextVAlignment::CENTER);
    texto->setAnchorPoint(Vec2(1,1));
    texto->setPosition(panelPalabras->getContentSize().width+margenPanelPalabrasInterno,panelPalabras->getContentSize().height-((panelPalabras->getChildrenCount()*(100+margenPanelPalabrasInterno))+(margenPanelPalabrasInterno*5)));
    //texto->setPosition(0,0);
    panelPalabras->addChild(texto);
    
}
Esempio n. 28
0
LabelTTF * LabelTTF::create()
{
    LabelTTF * ret = new LabelTTF();
    if (ret && ret->initWithString("", "assets/fonts/DroidSansFallback.ttf", 12, Size::ZERO, TextHAlignment::CENTER, TextVAlignment::TOP))
	{
		ret->autorelease();
		return ret;
	}
	CC_SAFE_DELETE(ret);
	return nullptr;
}
Esempio n. 29
0
LabelTTF * LabelTTF::createWithFontDefinition(const std::string& string, FontDefinition &textDefinition)
{
    LabelTTF *ret = new LabelTTF();
    if(ret && ret->initWithStringAndTextDefinition(string, textDefinition))
    {
        ret->autorelease();
        return ret;
    }
    CC_SAFE_DELETE(ret);
    return nullptr;
}
Esempio n. 30
0
void CCActionTest::testMove(Object *sender)
{
	log("testMove");
	
	LabelTTF *label = createTestLabel("Hello");

	MoveTo *move = MoveTo::create(3, Point(300, 300));
	
	label->runAction(move);
	
	hideMenu();
}