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
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;
}
示例#3
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;
}
示例#4
0
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
0
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
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;
}
示例#7
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);

}
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
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;
}
示例#10
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(); 
 
} 
示例#11
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;
}
示例#12
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;
	}
}
// 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
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);
	}
}
示例#15
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);
	}
示例#16
0
LabelTTF *CCActionTest::createTestLabel(const std::string &name)
{
	LabelTTF *label = LabelTTF::create(name, "Arial", 20);
	label->setPosition(Point(200, 200));
	addChild(label);
	return label;
}
示例#17
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;
}
示例#18
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;
}
示例#20
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++;

}
示例#21
0
TableViewCell* TableViewTestLayer::tableCellAtIndex(TableView *table, unsigned int idx)
{
    String *string = String::createWithFormat("%d", idx);
    TableViewCell *cell = table->dequeueCell();
    if (!cell) {
        cell = new CustomTableViewCell();
        cell->autorelease();
        Sprite *sprite = Sprite::create("Images/Icon.png");
        sprite->setAnchorPoint(Point::ZERO);
        sprite->setPosition(Point(0, 0));
        cell->addChild(sprite);

        LabelTTF *label = LabelTTF::create(string->getCString(), "Helvetica", 20.0);
        label->setPosition(Point::ZERO);
		label->setAnchorPoint(Point::ZERO);
        label->setTag(123);
        cell->addChild(label);
    }
    else
    {
        LabelTTF *label = (LabelTTF*)cell->getChildByTag(123);
        label->setString(string->getCString());
    }


    return cell;
}
示例#22
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;
}
示例#23
0
void SceneEditorTestLayer::onEnter()
{
    CCLayer::onEnter();

    // add title and subtitle
    std::string str = title();
    const char *pTitle = str.c_str();
    LabelTTF *label = LabelTTF::create(pTitle, "Arial", 18);
    label->setColor(Color3B(255, 255, 255));
    addChild(label, 1, 10000);
    label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );

    std::string strSubtitle = subtitle();
    if( ! strSubtitle.empty() )
    {
        LabelTTF *l = LabelTTF::create(strSubtitle.c_str(), "Arial", 18);
        l->setColor(Color3B(0, 0, 0));
        addChild(l, 1, 10001);
        l->setPosition(Point(VisibleRect::center().x, VisibleRect::top().y - 60) );
    }

    // add menu
    backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
    restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(SceneEditorTestLayer::restartCallback, this) );
    nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(SceneEditorTestLayer::nextCallback, this) );

    
    Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
    
    float fScale = 0.5f;
    
    menu->setPosition(Point(0, 0));
    backItem->setPosition(Point(VisibleRect::center().x - restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
    backItem->setScale(fScale);
    
    restartItem->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
    restartItem->setScale(fScale);
    
    nextItem->setPosition(Point(VisibleRect::center().x + restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
    nextItem->setScale(fScale);
    
    addChild(menu, 100);
    
    setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
}
示例#24
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;
}
示例#25
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);
}
示例#26
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);
}
Box2DTestLayer::Box2DTestLayer()
: _spriteTexture(NULL)
, world(NULL)
{
#if CC_ENABLE_BOX2D_INTEGRATION
    setTouchEnabled( true );
    setAccelerometerEnabled( true );

    // init physics
    this->initPhysics();
    // create reset button
    this->createResetButton();

    //Set up sprite
#if 1
    // Use batch node. Faster
    SpriteBatchNode *parent = SpriteBatchNode::create("Images/blocks.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png");
    Node *parent = Node::create();
#endif
    addChild(parent, 0, kTagParentNode);


    addNewSpriteAtPosition(VisibleRect::center());

    LabelTTF *label = LabelTTF::create("Tap screen", "Marker Felt", 32);
    addChild(label, 0);
    label->setColor(Color3B(0,0,255));
    label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y-50));
    
    scheduleUpdate();
#else
    LabelTTF *label = LabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION=1\n to run this test case",
                                            "Arial",
                                            18);
    Size size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
#endif
}
示例#28
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);
    
}
示例#29
0
bool StartLayer::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!Layer::init());
		Size winSize=Director::getInstance()->getWinSize();
		////labelttf *label1=labelttf::create("new game","arial",24*2);
		////menuitemlabel *pmenuitem = menuitemlabel::create(label1, this, menu_selector(startlayer::startgamecallback));
		////pmenuitem->settag(1);
		////pmenuitem->setposition(winsize.width / 2, winsize.height / 2);

        //Menu* pMenu = Menu::create(pMenuItem, NULL);
        //pMenu->setPosition(Vec2(0,0));
        //CC_BREAK_IF(! pMenu);
        //this->addChild(pMenu, 1);

		auto newGameItem = MenuItemImage::create("newgameA.png",
                                             "newgameB.png",
                                             CC_CALLBACK_1(StartLayer::startGameCallback, this));
		//newGameItem->setScale(0.5);
		newGameItem->setPosition(Point(winSize.width / 2, winSize.height / 2 - newGameItem->getContentSize().height*1));
		newGameItem->setEnabled(true);


		LabelTTF* pLabel = LabelTTF::create("Bubble Cat 2014", "Arial", 24 * 3);
        CC_BREAK_IF(! pLabel);
        pLabel->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
        this->addChild(pLabel, 1);

        Sprite* pSprite = Sprite::create("StartScene_CN.jpg");
        CC_BREAK_IF(! pSprite);
        pSprite->setPosition(Vec2(winSize.width/2, winSize.height/2));
       // this->addChild(pSprite, 0);

		auto closeItem = MenuItemImage::create(
												"CloseNormal.png",
												"CloseSelected.png",
												CC_CALLBACK_1(StartLayer ::menuCloseCallback, this));
    
		closeItem->setPosition(Vec2(winSize.width - closeItem->getContentSize().width/2 ,
									closeItem->getContentSize().height/2));

		// create menu, it's an autorelease object
		auto menu = Menu::create(closeItem,newGameItem, NULL);
		menu->setPosition(Vec2::ZERO);
		this->addChild(menu, 2);
		this->setVector();
        bRet = true;
	}while(0);
	return bRet;
}
示例#30
0
void LeaderBoardtNode::addItemToSlide(const int& iScore, const char* sName, const char* sFacebookId, const int& iRank, const int& iIndex)
{
    Node* pNodeItem = Node::create();

    Sprite* pLoadAvatar = Sprite::create("Target-End-Game/border_avatar.png");
    pLoadAvatar->setPosition(Point(50.0f, 95.0f));
    pNodeItem->addChild(pLoadAvatar);

    std::string urlAvatar = "https://graph.facebook.com/";
    urlAvatar.append(sFacebookId);
    urlAvatar.append("/picture");

    LoadingImagetNode* avatar = LoadingImagetNode::createLayout(urlAvatar.c_str());
    avatar->setPosition(Point(50.0f, 95.0f));
    pNodeItem->addChild(avatar);

    LabelBMFont *pLabelScore = LabelBMFont::create(formatNumber(iScore).getCString(), "fonts/font_small_alert.fnt");
    pLabelScore->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelScore->setPosition(Point(57.0f, 8.0f));
    pLabelScore->setScale(0.8);
    pNodeItem->addChild(pLabelScore);

    LabelTTF *pLabelName = LabelTTF::create(sName, "Arial", 20.0f);
    pLabelName->setColor(ccc3(0.0f, 0.0f, 0.0f));
    //pLabelName->setScale(0.85f);
    pLabelName->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelName->setPosition(Point(57.0f, 45.0f));
    pNodeItem->addChild(pLabelName);

    char sRank[10];
    sprintf(sRank, "%d", iRank);
    LabelBMFont *pLabelRank = LabelBMFont::create(sRank, "fonts/font-bechic.fnt");
    pLabelRank->setAnchorPoint(Point(0.0f, 0.5f));
    pLabelRank->setPosition(Point(25.0f, 23.0f));
    pNodeItem->addChild(pLabelRank);

    Sprite* pLineImage = Sprite::create("Target-End-Game/line.png");
    pLineImage->setPosition(Point(160.0f, 55.0f));
    pNodeItem->addChild(pLineImage);

    pNodeItem->setContentSize(Size(160.0f, 160.0f));
    pNodeItem->setPosition(Point(-320.0f + iIndex*160, -100.0f));
    pNodeItem->setTag(iIndex);
    m_pSlideShow->addChild(pNodeItem);

    Sprite* pIconAskLife = Sprite::create("Target-End-Game/btn_ask_life.png");
    ButtonNode* pButtonAskLife = ButtonNode::createButtonSprite(pIconAskLife, CC_CALLBACK_1(LeaderBoardtNode::clickAskLife, this));
    pButtonAskLife->setPosition(Point(-205.0f + iIndex*160, -5.0f));
    m_pButtonManagerNode->addButtonNode(pButtonAskLife);
}