Ejemplo n.º 1
0
void gdShow::ButonCallback(Ref* resender)
{
	//如果当前是最后一张图片,点按钮就直接开始游戏
	if (this->getChildByTag(4)->getPositionX() == Director::getInstance()->getVisibleSize().width / 2)
	{
		auto sc = GameScene::createSceneWithId(2);
		auto reScene = TransitionJumpZoom::create(0.0f, sc);
		Director::getInstance()->replaceScene(sc);
		CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sound/Blip.wav");
		auto m = (MenuItemSprite*)resender;
		m->setEnabled(false);
		return;
	}


	CocosDenshion::SimpleAudioEngine::getInstance()->playEffect("sound/Blip.wav");
	MenuItemImage* m = (MenuItemImage*)resender;
	m->setEnabled(false);
	CallFunc* call = CallFunc::create([&](){nextMenuItem->setEnabled(true); });
	MoveBy* moveby1 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby2 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby3 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	MoveBy* moveby4 = MoveBy::create(0.4f, Vec2(-Director::getInstance()->getVisibleSize().width, 0));
	this->getChildByTag(2)->runAction(EaseSineInOut::create(moveby2));
	this->getChildByTag(3)->runAction(EaseSineInOut::create(moveby3));
	this->getChildByTag(4)->runAction(EaseSineInOut::create(moveby4));
	this->getChildByTag(1)->runAction(EaseSineInOut::create(Sequence::create(moveby1, call, NULL)));
}
Ejemplo n.º 2
0
//TODO 屏蔽事件穿透
void BattleScene::createBottomBar()
{
	LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100));
	bottom->setContentSize(Size(WINSIZE.width, 120));
	bottom->setPosition(Point(0, 0));
	addChild(bottom);

	int totalCount = 11;
	int index = 0;
	Vector<MenuItem *> items;
	auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp();
	map<int, vector<DSoldier *>>::iterator it;
	for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++)
	{
		MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this));
		item->setTag(it->first);
		items.pushBack(item);
		index++;

		//head
		Size size = item->getContentSize();
		char img[20];
		sprintf(img, "ui/%d.png", it->first / 100);
		auto head = Sprite::create(img);
		head->setAnchorPoint(Point(0.5, 0.5));
		head->setPosition(size.width/2, size.height/2);
		item->addChild(head);
		
		char text[20];
		sprintf(text, "X %d", it->second.size());
		TTFConfig config("fonts/tahoma.ttf",16);
		auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT);
		count->setPosition(size.width/2, size.height - count->getContentSize().height);
		item->addChild(count);
		//初始化为第一个兵种
		if (m_selectedSoldierType <= 0)
		{
			m_selectedSoldierType = it->first;
		}
		
	}
	for (int i = index; i < totalCount; i++)
	{
		MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this));
		item->setEnabled(false);
		items.pushBack(item);
	}

	Size bottomSize = bottom->getContentSize();
	Sprite *spItem = Sprite::create("ui/618.0.png");
	Size itemSize = spItem->getContentSize();
	float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1);

	UIRadioButton *radio = UIRadioButton::createWithArray(items);
	radio->alignItemsHorizontallyWithPadding(padding);
	radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2));
	radio->setSelectedIndex(0);
	bottom->addChild(radio);
}
Ejemplo n.º 3
0
void GameMenu::menuEnter(){
    Node* mainmenu = this->getChildByTag(3);
    //CCArray* temp = mainmenu->getChildren();
    Vector<Node*> temp = mainmenu->getChildren();
    
    for(int i = 0;i < (int)(temp.size());i ++)
    {
        
       //MenuItemImage *item = (MenuItemImage *)temp[i];
        MenuItemImage *item = (MenuItemImage *)temp.at(i);
      item->setEnabled(true);
    }

}
Ejemplo n.º 4
0
bool SelectTowerLayer::init()
{
	if (!Layer::init())
	{
		return false;
	}
	 
	// show the position for tower
	auto towerPos = Sprite::create("towerPos.png");
	towerPos->setScale(0.7);
	//towerPos->setAnchorPoint(Vec2::ZERO);
	this->addChild(towerPos);

	menu = Menu::create();

	//according to Towers  to create equal num menuItems and the Sprite
	auto instance = GameManager::getInstance();
	int nums = instance->towerSelectVector.size();

	int currmoney = dynamic_cast<UiLayer*>(GameManager::getInstance()->getUiLayer())->getcurmoney();
	
	for (int i = 0; i < nums; i++)
	{
		int tower_count = instance->towerSelectVector.at(i);
		MenuItemImage* towerItem = MenuItemImage::create(StringUtils::format("startUI/tower__%02d.png", tower_count), StringUtils::format("startUI/tower__%02d.png", tower_count), StringUtils::format("startUI/tower__%02dunabled.png", tower_count), [=](Ref*)
		{			
			log("You select the %d", tower_count);
			//to assign the choose value when touch the menuItem
			addTower(tower_count);
			//clear up the contents
			 
			//this->removeAllChildrenWithCleanup(true);
			Layer::removeFromParent();
		});
		//judge this gold 
		switch (tower_count)
		{
		case 1:
			if (currmoney < TOWERONECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 2:
			if (currmoney < TOWERTWOCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 3:
			if (currmoney < TOWERTHREECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 4:
			if (currmoney < TOWERFORECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 5:
			if (currmoney < TOWERFIVECOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 6:
			if (currmoney < TOWERSIXCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 7:
			if (currmoney < TOWERSEVENCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		case 8:
			if (currmoney < TOWEREIGHTCOST)
			{
				towerItem->setEnabled(false);
			}
			break;
		default:
			break;
		}
		
		int pos_x = i * 64;
		int pos_y = +64 * (i / 3 + 0);

		pos_x = pos_x - 3 * 64 * ((i / 3 + 0));

		towerItem->setPosition(pos_x, pos_y);
		menu->addChild(towerItem);
	}
	menu->setAnchorPoint(Vec2::ZERO);
	menu->setPosition(Vec2(-towerPos->getContentSize().width / 3 * 2, towerPos->getContentSize().height / 3 * 2));
 	this->addChild(menu);

	return true;
}