Exemplo n.º 1
0
bool BowManHightScore::init()
{
	if(!Layer::init()){
		return false;
	}


	Size visibleSize = Director::getInstance()->getVisibleSize();

	Sprite* backSprite1 = Sprite::create("img/button/back_btn.png");
	Sprite* backSprite2 = Sprite::create("img/button/back_btn1.png");


	MenuItemSprite* backBtn = MenuItemSprite::create(
		backSprite1 , 
		backSprite2 ,
		CC_CALLBACK_1(BowManHightScore::backCallback , this)
		);

	backBtn->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
	backBtn->setPosition(Vec2(
		10 + backBtn->getContentSize().width/2 ,
		visibleSize.height - 10 - backBtn->getContentSize().height/2
		));

	Menu* menu = Menu::create(
		backBtn,
		NULL
		);

	this->addChild(menu);

	return true;
}
//pageview的用法
void TeachingLayer::addLayer(int index)
{
	auto winSize = Director::getInstance()->getWinSize();
	pageView = PageView::create();
	//一定要设置大小,不然看不见
	pageView->setContentSize(winSize);
	pageView->setBackGroundColor(Color3B::GREEN);
	pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
	pageView->removeAllPages();
	pageView->setPosition(Vec2::ZERO);
	if (index == 0)
	{
		for (int i=0;i<4;++i)
		{
			//pageview一定要配合layout使用
			Layout* layout = Layout::create();
			layout->setContentSize(winSize);
			auto layer = TeachingSubLayer::create(index,i);
			//layer->setPosition(Vec2(winSize.width/2,winSize.height/2));
			layout->addChild(layer);
			//----按钮
			MenuItemSprite* pJumpItem;
			if (i<=2)
			{
				auto nextNormal = Sprite::create("teaching_next.png");
				auto nextPressed = Sprite::create("teaching_next.png");
				nextPressed->setScale(1.4f);
				pJumpItem = MenuItemSprite::create(nextNormal,nextPressed,CC_CALLBACK_0(TeachingLayer::menuJump,this));
				//pJumpItem->setPosition(Vec2(winSize.width/2 - 60,35-winSize.height/2));
				pJumpItem->setPosition(Vec2(winSize.width - pJumpItem->getContentSize().width,
					pJumpItem->getContentSize().height));
			}
			else//最后一步
			{
				auto nextNormal = Sprite::create("teaching_enter.png");
				auto nextPressed = Sprite::create("teaching_enter.png");
				nextPressed->setScale(1.4f);
				pJumpItem = MenuItemSprite::create(nextNormal,nextPressed,CC_CALLBACK_0(TeachingLayer::menuJump,this));
				pJumpItem->setPosition(Vec2(winSize.width - pJumpItem->getContentSize().width,
					pJumpItem->getContentSize().height));
			}
			pJumpItem->setAnchorPoint(Vec2::ANCHOR_BOTTOM_RIGHT);

			auto pMenu = Menu::create(pJumpItem,nullptr);
			pMenu->setPosition(Vec2::ZERO);
			layer->addChild(pMenu,3);

			pageView->insertPage(layout,i);
		}
	}

	curPage = 0;
	pageView->scrollToPage(curPage);
	pageView->addEventListener(CC_CALLBACK_2(TeachingLayer::pageViewEvent, this));

	this->addChild(pageView);
}
Exemplo n.º 3
0
bool BowManInforGame::init()
{
    if(!Layer::init())
    {
        return false;
    }

    /////////////////////////////////////////////////////////////////
    // BACKGROUNG INFO
    /////////////////////////////////////////////////////////////////

    Sprite* background = Sprite::create("img/background/bg_info.png");
    background->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    background->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2));
    this->addChild(background);


    /////////////////////////////////////////////////////////////////
    // DIALOG INFO
    /////////////////////////////////////////////////////////////////

    Sprite* infoDialog = Sprite::create("img/dialog/info_dialog.png");
    infoDialog->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    infoDialog->setPosition(Vec2(WINSIZE.width/2 , WINSIZE.height/2));
    this->addChild(infoDialog);



    /////////////////////////////////////////////////////////////////
    // BACK BUTTON
    /////////////////////////////////////////////////////////////////

    Sprite* backSprite1 = Sprite::create("img/button/back_btn.png");
    Sprite* backSprite2 = Sprite::create("img/button/back_btn1.png");

    MenuItemSprite* backBtn = MenuItemSprite::create(
                                  backSprite1,
                                  backSprite2,
                                  CC_CALLBACK_1(BowManInforGame::backCallback, this)
                              );

    backBtn->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
    backBtn->setPosition(Vec2(
                             10 + backBtn->getContentSize().width / 2,
                             WINSIZE.height - 10 - backBtn->getContentSize().height / 2
                         ));

    Menu* menu = Menu::create(backBtn,NULL);

    this->addChild(menu);

    return true;
}
Exemplo n.º 4
0
bool HomeLayer::init(){
    bool isDay = UserDefault::getInstance()->getBoolForKey(DayTime, true);
    string file = "modify/day_bg.png";
    if (isDay == false) {
        file = string("modify/night_bg.png");
    }
    if (GameLayerBase::initWithBgFileName(file.c_str())) {
        
        Sprite* centerTitle = Sprite::create("modify/title.png");
        centerTitle->setAnchorPoint(Vec2(0.5, 1.0));
        centerTitle->setPosition(STVisibleRect::getCenterOfScene().x, STVisibleRect::getPointOfSceneLeftUp().y - 60);
        addChild(centerTitle, 1);
  
//
//        TableViewTest* pLayer = TableViewTest::create();
//        this->addChild(pLayer, 2);
        MenuItemSprite* lightBtn = CocosHelper::menuItemSprite("modify/night.png");
        MenuItemSprite* settingBtn = CocosHelper::menuItemSprite("modify/setting.png");
        MenuItemSprite* vedioBtn = CocosHelper::menuItemSprite("modify/video.png");
        string soundFile = "modify/sound1.png";
        if (!SoundPlayer::getInstance()->isMusicOpen()) {
            soundFile = "modify/sound2.png";
        }
        MenuItemSprite* soundBtn = CocosHelper::menuItemSprite(soundFile.c_str());
        MenuItemSprite* shareBtn = CocosHelper::menuItemSprite("modify/share.png");

        lightBtn->setTag(kLightBtnTag);
        settingBtn->setTag(kSettingBtnTag);
        vedioBtn->setTag(kVedioBtnTag);
        soundBtn->setTag(kSoundBtnTag);
        shareBtn->setTag(kShareBtnTag);
        
        lightBtn->setAnchorPoint(Vec2(0, 0));
        settingBtn->setAnchorPoint(Vec2(1.0, 0));
        vedioBtn->setAnchorPoint(Vec2(0.5, 0));
        soundBtn->setAnchorPoint(Vec2(1.0, 0));
        shareBtn->setAnchorPoint(Vec2(1.0, 0));
        
        lightBtn->setPosition(Vec2(STVisibleRect::getOriginalPoint().x + 15, 60*0.618+STVisibleRect::getOriginalPoint().y));
        settingBtn->setPosition(Vec2(STVisibleRect::getPointOfSceneRightBottom().x - 15, 60*0.618 + STVisibleRect::getOriginalPoint().y));
        vedioBtn->setPosition(Vec2(STVisibleRect::getCenterOfScene().x, lightBtn->getBoundingBox().getMaxY() + 15));
        soundBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
        shareBtn->setPosition(settingBtn->getPosition()+Vec2(15, 0));
        
        lightBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
        settingBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
        vedioBtn->setCallback(CC_CALLBACK_1(HomeLayer::onClickedMenuItems, this));
        
        
        Menu* pBtns = Menu::create(lightBtn, settingBtn, vedioBtn, NULL);
        pBtns->setAnchorPoint(Vec2(0, 0));
        pBtns->setPosition(Vec2(0, 0));
        addChild(pBtns, 2);
        
        float maxHeight = centerTitle->getBoundingBox().getMidY() - vedioBtn->getBoundingBox().getMaxY();
        log("the max height is %.2f", maxHeight);

        float tableHeight = maxHeight - 100*1.618;
        float tableWidth = STVisibleRect::getGlvisibleSize().width - 200*0.618;
        
        log("the tablewidth is %.2f, and the tableheight is %.2f", tableWidth, tableHeight);
        int w = (int)tableWidth;
        int h = (int)tableHeight;
        
        TableViewTest* pLayer = TableViewTest::create(Size(w, h));
        pLayer->setPosition(Vec2(100*0.618 + STVisibleRect::getOriginalPoint().x, vedioBtn->getBoundingBox().getMaxY() + 100*0.618));
        addChild(pLayer, 10);
        pLayer->setDelegate(this);
        return true;
    }
    return false;
}
Exemplo n.º 5
0
void PlayLayer::initToolLayer()
{
	auto size = Director::getInstance()->getWinSize();
	//add by  
	auto zoom = size.height / 864;
	toolLayer = Layer::create();
	addChild(toolLayer);

	spritetool = Sprite::createWithSpriteFrameName("status.png");
	//auto spritetool = Sprite::create("status.png");

	//add by  
	auto statussize=spritetool->getContentSize();
	//auto patchsize=(size.width - statussize.width)/2;

	spritetool->setAnchorPoint(Point(0.5f, 1));
	spritetool->setPosition (Point(size.width / 2, size.height));
	toolLayer->addChild(spritetool);

	//金币像素 54;波数370,分数 484;怪数 684,分数 790;生命1060,add by  
	money = instance->getMoney();
	moneyLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	// moneyLabel->setPosition(Point(spritetool->getContentSize().width / 8, spritetool->getContentSize().height / 2));
	//由于该图片被整体所放过,所有要相应进行像素处理。
	moneyLabel->setPosition(Point( 54* zoom, spritetool->getContentSize().height / 2));
	moneyLabel->setAnchorPoint(Point(0, 0.5f));
	//modify by  
	char countBuf3[16] = "";
	sprintf(countBuf3, "%d", money);
	auto moneyText = countBuf3;
	//
	//auto moneyText = std::to_string(money);
	moneyLabel->setString(moneyText);
	spritetool->addChild(moneyLabel);


	//波数的分数
	//int groupTotal = instance->getGroupNum();	
	int temp =1;
	char countBuf5[16] = "";
	sprintf(countBuf5, "%d",temp);
	groupcurrLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	auto groupInfoText2 = countBuf5;
	groupcurrLabel->setPosition(Point(370 * zoom , spritetool->getContentSize().height / 2 ));
	groupcurrLabel->setAnchorPoint(Point(0.0f , 0.5f));
	groupcurrLabel->setString(groupInfoText2);
	spritetool->addChild(groupcurrLabel);
	//总共波数
	int groupTotal = instance->getGroupNum();
	groupLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	groupLabel->setPosition(Point(484 * zoom , spritetool->getContentSize().height / 2 ));
	groupLabel->setAnchorPoint(Point(0.0f , 0.5f));
	char countBuf4[16] = "";
	sprintf(countBuf4, "%d", groupTotal);
	auto groupInfoText = countBuf4;
	groupLabel->setString(groupInfoText);
	spritetool->addChild(groupLabel);








	//by  
	//当前波的怪物
	char countBuf6[16] = "";
	sprintf(countBuf6, "%d", temp);
	auto groupTotalText3 = countBuf6;	
	numcurrLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	numcurrLabel->setPosition(Point( 684 * zoom , spritetool->getContentSize().height / 2 ));
	numcurrLabel->setAnchorPoint(Point(0.0f , 0.5f));
	numcurrLabel->setString(groupTotalText3);
	spritetool->addChild(numcurrLabel);

	//当前波的怪物 分数
	char countBuf7[16] = "";
	auto en= instance->getEnemyNum();	
	sprintf(countBuf7, "%d", en);
	auto groupTotalText4 = countBuf7;	
	numLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	numLabel->setPosition(Point( 790 * zoom , spritetool->getContentSize().height / 2 ));
	numLabel->setAnchorPoint(Point(0.0f , 0.5f));
	numLabel->setString(groupTotalText4);
	spritetool->addChild(numLabel);

	//当前生命值的 分数
	char countBuf8[16] = "";
	sprintf(countBuf8, "100");
	auto groupTotalText5 = countBuf8;	
	hpLabel = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", " ");
	hpLabel->setPosition(Point( 1060 * zoom , spritetool->getContentSize().height / 2 ));
	hpLabel->setAnchorPoint(Point(0.0f , 0.5f));
	hpLabel->setString(groupTotalText5);
	spritetool->addChild(hpLabel);




	// back
	//add by  
	Sprite *backItem1 = CCSprite::createWithSpriteFrameName("btn_back.png");
	Sprite *backItem2 = CCSprite::createWithSpriteFrameName("btn_back_press.png");
	MenuItemSprite *pPauseItem = MenuItemSprite::create(backItem1, backItem2, CC_CALLBACK_1(PlayLayer::menuBackCallback, this));
	pPauseItem->setPosition(Point(spritetool->getContentSize().width + backItem1->getContentSize().width / 2, spritetool->getContentSize().height / 2));

	pPauseItem->setAnchorPoint(Point(0, 0.5f));
	Menu* pMenu = Menu::create(pPauseItem, NULL);
	pMenu->setPosition(Point::ZERO);
	spritetool->addChild(pMenu);
}