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


C++ CCMenuItemImage::boundingBox方法代码示例

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


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

示例1:

CCMenuItemImage* Objects2dFactory::imageButton(CCNode* scene, CCMenu* menu, string normalImagePath, string selectedImagePath, string disabledImagePath, 
	float positionX, float positionY, float width, float height, SEL_MenuHandler selector, void* selectorArg, AlignX alignX, AlignY alignY, int zOrder)
{
	// Check arguments validity
	if(scene == NULL || menu == NULL || !selector)
		return NULL;

	// Create a button menu item
    CCMenuItemImage *button = CCMenuItemImage::create(
        normalImagePath.c_str(),
        selectedImagePath.c_str(),
        disabledImagePath.c_str(),
        scene,
        selector);
    if(!button)
		return NULL;

	if (selectorArg != NULL)
	{
		button->setUserData(selectorArg);
	}

    // Place the menu item in the given position
    button->setPosition(ccp(positionX, positionY));

	// Set anchor
	button->setAnchorPoint(ccp(Constants::getAnchorValue(alignX), Constants::getAnchorValue(alignY)));
	
	// Set menu item width
	float buttonWidth = button->boundingBox().size.width;
	if (width > 0) // if width is defined, it is setted
	{
		button->setScaleX(width / buttonWidth);
	}

	// Set menu item height
	float buttonHeight = button->boundingBox().size.height;
	if (height > 0) // if height is defined, it is setted
	{
		button->setScaleY(height / buttonHeight);
	}

	// Add button to the menu
	menu->addChild(button, zOrder);

	return button;
}
开发者ID:Cnotinfor,项目名称:TopQX_2D,代码行数:47,代码来源:Objects2dFactory.cpp

示例2: init

// on "init" you need to initialize your instance
bool Start::init()
{
	mScreenSize = CCDirector::sharedDirector()->getWinSize();

	for (int i = 0; i<gbackgroundNum; i++)
	{
		CCSprite *pbackGround = CCSprite::create("daybackground.png"); 
		CCRect rcBounding = pbackGround->boundingBox();  
		pbackGround->setPosition(ccp(rcBounding.size.width*(i*2+1) / 2, mScreenSize.height / 2));    
		this->addChild(pbackGround);   
	}
	
	CCSize groundSize;
	for (int i = 0; i<ggroundNum; i++)
	{
		pGround[i] = CCSprite::create("ground.png");
		groundSize = pGround[i]->getContentSize();
		pGround[i]->setPosition(ccp(groundSize.width*(i*2+1) / 2, groundSize.height / 2));    
		this->addChild(pGround[i],1);   
	}
	mbirdstr.push_back("birdblue");
	mbirdstr.push_back("birdred");
	mbirdstr.push_back("birdyellow");
	mbirdclolor=rand()%100%3;
	string strplist=mbirdstr[mbirdclolor]+".png";
	tbBird = CCSprite::create(strplist.c_str());
	tbBird->setPosition(ccp(mScreenSize.width/2,mScreenSize.height/2+10.));
	addChild(tbBird,0);
	initAction();
	CCMenuItemImage *tbstart = CCMenuItemImage::create("start.png", "start.png", this, menu_selector(Start::tbstartCallback) );
	tbstart->setPosition(ccp(mScreenSize.width/4,groundSize.height + 10 + tbstart->getContentSize().height/2));
    CCMenu* pMenu1 =CCMenu::create(tbstart, NULL);

    pMenu1->setPosition( CCPointZero );
   
	addChild(pMenu1);


	CCMenuItemImage *tbscore = CCMenuItemImage::create("top.png", "top.png", this, menu_selector(Start::tbtopCallback) );
	tbscore->setPosition(ccp(mScreenSize.width*3/4,groundSize.height+10 + tbscore->getContentSize().height/2));
    CCMenu* pMenu2 =CCMenu::create(tbscore, NULL);

    pMenu2->setPosition( CCPointZero );
   
	addChild(pMenu2);

	CCSprite *m_pFlappyBird = CCSprite::create("flappybird.png");     
	//CCSprite *m_pFlappyBird = CCSprite::create("sprites.png",CCRectMake(0,680,180,55));     
	CCRect rcBounding = m_pFlappyBird->boundingBox();
	float fFlappyBirdHeight=rcBounding.size.height/2.0f;
	float xpos=mScreenSize.width/2;
	float ypos=mScreenSize.height*3/4+20;

	m_pFlappyBird->setPosition(ccp(xpos,  ypos));    // 设置在屏幕中间  
	this->addChild(m_pFlappyBird);  

	CCSprite*m_pRate = CCSprite::create("rate.png");     
	rcBounding = m_pRate->boundingBox();
	CCSize startSize = m_pRate->getContentSize();
	float fRateWidth=rcBounding.size.width/2.0f;
	float fRateHeight=rcBounding.size.height/2.0f;
	xpos=mScreenSize.width/2.0f;
	ypos=tbscore->boundingBox().getMaxY()+fRateHeight+10;
	m_pRate->setPosition(ccp(xpos,  ypos));    // 设置在屏幕中间  
	this->addChild(m_pRate);  


	scheduleUpdate();
	
	//CCActionInterval*  actionTo = CCMoveBy::create(0.5, ccp(0, 10));
	//CCActionInterval*  actionByBack = actionTo->reverse();

	//tbBird->runAction(CCRepeatForever::create(CCSequence::create( actionTo,actionByBack,NULL)));

	
	return true;
}
开发者ID:51anygo,项目名称:mybird,代码行数:78,代码来源:StartScence.cpp

示例3: init

// on "init" you need to initialize your instance
bool MainMenu::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->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
    //CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("MainMenu-ipadhd.plist");
    //_menuBatchNode = CCSpriteBatchNode::create("MainMenu-ipadhd.png");
    
    //this->addChild(_menuBatchNode);
    
    auto CCSprite * sprite;
    sprite = CCSprite::create("mainmenucolor.png");
    sprite->setRotation(90.0f);
    sprite->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
    this->addChild(sprite,0);
    
    sprite = CCSprite::create("mainmenubull.png");
    sprite->setPosition(ccp(visibleSize.width/2-sprite->boundingBox().size.width/2.5,visibleSize.height-sprite->boundingBox().size.height/2));
    sprite->setScale(.95f);
    this->addChild(sprite);
    
    //sprite = CCSprite::createWithSpriteFrameName("playButton.png");
    //sprite->setPosition(ccp(visibleSize.width/2+sprite->boundingBox().size.width/2,visibleSize.height/2+sprite->boundingBox().size.height/2));
    //_menuBatchNode->addChild(sprite);
    
    
    CCMenuItemImage *playbutton = CCMenuItemImage::create("playButton.png","playButton.png",this,menu_selector(MainMenu::playButtonCallback));
    playbutton->setPosition(ccp(visibleSize.width/2+playbutton->boundingBox().size.width/2,visibleSize.height/2+playbutton->boundingBox().size.height/2));
    
    CCMenu* playMenu = CCMenu::create(playbutton, NULL);
    playMenu->setPosition(CCPointZero);
    this->addChild(playMenu, 1);
    
    CCMenuItemImage *quitbutton = CCMenuItemImage::create("quitbutton.png","quitbutton.png",this,menu_selector(MainMenu::menuCloseCallback));
    
    quitbutton->setPosition(ccp(visibleSize.width/2+quitbutton->boundingBox().size.width/2,visibleSize.height/4));
    
    CCMenu* quitMenu = CCMenu::create(quitbutton, NULL);
    quitMenu->setPosition(CCPointZero);
    this->addChild(quitMenu, 1);
    
    
    
    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    

    
    
    return true;
}
开发者ID:xgeraldx,项目名称:ChickenHunt,代码行数:69,代码来源:MainMenuScene.cpp


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