本文整理汇总了C++中CCMenuItemSprite::getContentSize方法的典型用法代码示例。如果您正苦于以下问题:C++ CCMenuItemSprite::getContentSize方法的具体用法?C++ CCMenuItemSprite::getContentSize怎么用?C++ CCMenuItemSprite::getContentSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCMenuItemSprite
的用法示例。
在下文中一共展示了CCMenuItemSprite::getContentSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool ProceedController::init(){
if (!CCLayer::init()) {
return false;
}
CCSize size = CCDirector::sharedDirector()->getWinSize();
//暂停按钮
CCMenuItemSprite *pause = this->instanceButton("pause1.png", "pause2.png", menu_selector(ProceedController::gamePauseFunc));
pause->setScale(1.5f);
pause->setPosition(ccp(size.width - pause->getContentSize().width,
size.height - pause->getContentSize().height));
//跳跃按钮
CCMenuItemSprite *jump = this->instanceButton("control_btn1.png", "control_btn2.png", menu_selector(ProceedController::gameJumpFunc));
jump->setScale(1.6f);
jump->setPosition(ccp(size.width - jump->getContentSize().width - 50, 100));
//fever按钮
CCMenuItemSprite *fever = this->instanceButton("Fever_1_1.png", "Fever_1_1.png",menu_selector(ProceedController::gameFeverFunc));
fever->setScale(1.5f);
fever->setOpacity(0.0f);
fever->setPosition(ccp(jump->getPosition().x - fever->getContentSize().width * 2.0,
jump->getPosition().y));
CCMenu *menu = CCMenu::create(pause,jump,fever,NULL);
menu->setPosition(0, 0);
this->addChild(menu,80);
return true;
}
示例2: createPlayAgainButton
void GameOverLayer::createPlayAgainButton()
{
// Create the startButton
CCSprite *playAgainButtonSpriteUp = CCSprite::createWithSpriteFrameName("playagain_button.png");
CCSprite *playAgainButtonSpriteDown = CCSprite::createWithSpriteFrameName("playagain_button.png");
// Scale the down to 90% so that it looks like the button was pressed
playAgainButtonSpriteDown->setScale(0.9f);
CCMenuItemSprite *playAgainButton = CCMenuItemSprite::create(playAgainButtonSpriteUp, playAgainButtonSpriteDown, this, menu_selector(GameOverLayer::playAgainButtonTouched));
playAgainButton->setPositionX(-playAgainButton->getContentSize().width/1.2);
playAgainButton->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleTo::create(1.0f, 1.2f), CCScaleTo::create(1.0f, 1.0f))));
// Create the mainButton
CCSprite *mainButtonSpriteUp = CCSprite::createWithSpriteFrameName("main_button.png");
CCSprite *mainButtonSpriteDown = CCSprite::createWithSpriteFrameName("main_button.png");
// Scale the down to 90% so that it looks like the button was pressed
mainButtonSpriteDown->setScale(0.9f);
CCMenuItemSprite *mainButton = CCMenuItemSprite::create(mainButtonSpriteUp, mainButtonSpriteDown, this, menu_selector(GameOverLayer::mainButtonTouched));
mainButton->setPositionX(mainButton->getContentSize().width/1.2);
// Create the start game menu
CCMenu *gameMenu = CCMenu::create(playAgainButton, mainButton, NULL);
// Set the initial position off screen
gameMenu->setPosition(ccp(SCREEN_WIDTH/2, -SCREEN_HEIGHT));
// Set the tag of the start menu so that we can refer to it later using getChildByTag(...)
gameMenu->setTag(kGameOverLayer_PlayAgainMenu);
// Create and run an animation that will slide the start game menu in from below the screen to its intended location
CCActionInterval *moveAction = CCMoveTo::create(0.3f, ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.15));
CCFiniteTimeAction *easeIn = CCEaseIn::create(moveAction, 0.2f);
gameMenu->runAction(easeIn);
// Add the start menu to the layer
this->addChild(gameMenu);
}
示例3: init
bool PanelLayer::init()
{
if (CCLayer::init()) {
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
_goldCounterLayer = GoldCounterLayer::create();
this->addChild(_goldCounterLayer);
ScheduleCountDown *scheduleCountDown = ScheduleCountDown::create(this);
_scheduleLabel = CCLabelTTF::create("60", "Thonburi", 16);
_scheduleLabel->addChild(scheduleCountDown);
this->addChild(_scheduleLabel);
CCMenuItemSprite *pause = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("pause_normal")), CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("pause_selected")), this, menu_selector(PanelLayer::pause));
CCMenu *menu = CCMenu::create(pause, NULL);
this->addChild(menu);
_goldCounterLayer->setPosition(CCPointMake(winSize.width*0.05f, winSize.height*0.05f));
_scheduleLabel->setPosition(CCPointMake(winSize.width*0.3f, winSize.height*0.05f));
CCSize pauseSize = pause->getContentSize();
menu->setPosition(CCPointMake(winSize.width-pauseSize.width*0.5f, pauseSize.height*0.5f));
return true;
}
return false;
}
示例4: loadUI
void BYGameScene::loadUI() {
CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
frameCache->addSpriteFramesWithFile("ui.plist", "ui.png");
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
/// pause button
CCSprite* btnNormalSprite = CCSprite::createWithSpriteFrameName("pause.png");
CCMenuItemSprite *pauseMenuItem = CCMenuItemSprite::create(btnNormalSprite,
btnNormalSprite,
this,
menu_selector(BYGameScene::pauseButtonHandler));
/// 2 labels for goals
ccColor3B color = ccc3(220, 70, 20); /// red color
_labelBotPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
_labelBotPlayerGoalsScored->setColor(color);
CCMenuItemLabel *labelBot = CCMenuItemLabel::create(_labelBotPlayerGoalsScored, NULL, NULL);
labelBot->setEnabled(false);
_labelTopPlayerGoalsScored = CCLabelTTF::create("0", "Marker Felt", 40);
_labelTopPlayerGoalsScored->setColor(color);
CCMenuItemLabel *labelTop = CCMenuItemLabel::create(_labelTopPlayerGoalsScored, NULL, NULL);
labelTop->setEnabled(false);
/// CCMenu doesnt support anchorPoint as of 0x00020003 version
CCMenu *menu = CCMenu::create(labelTop, pauseMenuItem, labelBot, NULL);
menu->alignItemsHorizontallyWithPadding(5);
menu->setAnchorPoint(CCPointMake(0, 0));
menu->setPosition(CCPointMake(winSize.width - pauseMenuItem->getContentSize().width / 2,
winSize.height / 2));
menu->setRotation(90);
this->addChild(menu);
}
示例5: displayDetail
void MyBuildingCard::displayDetail(cocos2d::CCNode *psender){
MyBuildingCard* card = (MyBuildingCard*)psender->getParent()->getParent();
activeCard = card;
oriPosition = card->getPosition();
card->runAction(CCEaseInOut::create(CCMoveTo::create(0.2, ccp(200-card->getParent()->getPosition().x,320)),2));
card->runAction(CCEaseInOut::create(CCScaleTo::create(0.2, 1.2),2));
card->isEnabled = false;
((GXScrollView*)(card->getParent()))->setEnabled(false);
card->getParent()->reorderChild(card, 100000);
CCMenuItemSprite* gray = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("dialoggray.png"), CCSprite::createWithSpriteFrameName("dialoggray.png"));
MyPriorityMenu* grayMenu = MyPriorityMenu::create(-503,gray,NULL);
grayMenu->setTag(grayTag);
card->getParent()->addChild(grayMenu,99999);
gray->setScaleX(960/gray->getContentSize().width);
gray->setScaleY(540/gray->getContentSize().height);
grayMenu->setPosition(ccp(480-card->getParent()->getPosition().x,320));
// gray->setPosition(ccp(0,0));
CCSprite* detailBack = CCSprite::createWithSpriteFrameName("creatoruidetail.jpg"); detailBack->setPosition(ccp(634-card->getParent()->getPosition().x,-detailBack->getContentSize().height/2-100));
detailBack->setScale(1.2);
detailBack->setTag(detailBackTag);
card->getParent()->addChild(detailBack,100000);
detailBack->runAction(CCSequence::create(CCDelayTime::create(0.2),CCEaseInOut::create(CCMoveTo::create(0.2, ccp(634-card->getParent()->getPosition().x,320)),2), NULL));
CCMenuItemFont::setFontSize(24);
CCMenuItemFont* back = CCMenuItemFont::create("返回",this,menu_selector(MyBuildingCard::cancelDetail));
back->setColor(ccc3(114,66,45));
MyPriorityMenu* backMenu = MyPriorityMenu::create(-503,back,NULL);
backMenu->setPosition(ccp(detailBack->getContentSize().width-44,44));
detailBack->addChild(backMenu,NULL);
}
示例6: init
// on "init" you need to initialize your instance
bool AchievementLayer::init() {
if (!CCLayerColor::initWithColor(ccc4(100, 255, 255, 255)))
return false;
_achievementAchievementsLayer = NULL;
//adding the background
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
cocos2d::CCSprite* backgroundArt = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("menuBackground.png"));
float bgScale = winSize.height / backgroundArt->getContentSize().height;
backgroundArt->setScale(bgScale);
float diff = winSize.width - backgroundArt->getContentSize().width * bgScale;
float x = backgroundArt->getContentSize().width / 2 * bgScale + diff / 2;
float y = backgroundArt->getContentSize().height / 2 * bgScale;
backgroundArt->setPosition(ccp(x, y));
addChild(backgroundArt);
float scaleMult = Model::getInstance()->getGUIElementScaleMultiplicator();
//back button
int buttonHeight = 66 * scaleMult;
int buttonLength = 66 * scaleMult;
CCMenu* backButtonmenu = CCMenu::create();
CCMenuItemSprite *backButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("return0.png"),
CCSprite::createWithSpriteFrameName("return1.png"), (CCObject*) this, menu_selector(AchievementLayer::backTouched));
backButton->setScaleX(buttonLength / backButton->getContentSize().width);
backButton->setScaleY(buttonHeight / backButton->getContentSize().height);
backButtonmenu->addChild(backButton);
CCMenuItemSprite *toggleModeButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("toggleGUI1.png"),
CCSprite::createWithSpriteFrameName("toggleGUI2.png"), (CCObject*) this, menu_selector(AchievementLayer::toggleModeTouched));
toggleModeButton->setScaleX(buttonLength / toggleModeButton->getContentSize().width);
toggleModeButton->setScaleY(buttonHeight / toggleModeButton->getContentSize().height);
backButtonmenu->addChild(toggleModeButton);
float padding = 10 * scaleMult;
backButtonmenu->alignItemsVerticallyWithPadding(padding);
addChild(backButtonmenu);
backButtonmenu->setPosition(CCPoint(winSize.width - buttonLength / 2, winSize.height - (buttonHeight * 2.0f + padding) / 2));
float offsetDown = ViewTools::addVersionAndCreditInfo(this, scaleMult);
ViewTools::addIdleUnitTo(this, offsetDown);
return true;
}
示例7: init
bool PanelLayer::init()
{
if(CCLayer::init()){
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCMenuItemSprite* pause = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("pause_normal")), CCSprite::createWithSpriteFrameName(STATIC_DATA_STRING("pause_selected")),this,menu_selector(PanelLayer::pause));
CCMenu* menu = CCMenu::create(pause, NULL);
this->addChild(menu);
CCSize pauseSize = pause->getContentSize();
menu->setPosition(CCPointMake(winSize.width-pauseSize.width*0.5, pauseSize.height*0.5));
return true;
}
return false;
}
示例8: sprintf
CCMenuItemSprite *CWaterpump::initMenuItemWithFiles(int type, const char *normal, const char *selected, const char *disable, SEL_MenuHandler selector)
{
CCSprite *pNormal = CCSprite::create(normal);
CCSprite *pSelected = CCSprite::create(selected);
CCSprite *pDisable = CCSprite::create(disable);
CCMenuItemSprite *pItem = CCMenuItemSprite::create(pNormal, pSelected, pDisable, this, selector);
int cnt = CPlayerAccount::GetAccountInstance()->GetAccountPropsNum(type);
char szCntStr[8] = {0};
sprintf(szCntStr, "%d", cnt);
CCLabelAtlas *pCntFnt = CCLabelAtlas::create(szCntStr, "UI_02_05.png", 48, 57, '0');
pCntFnt->setAnchorPoint(ccp(1, 0));
pCntFnt->setPosition(ccp(pItem->getContentSize().width, 0));
pItem->addChild(pCntFnt, 1, Tag_ItemFnt);
pItem->setTag(type);
return pItem;
}
示例9: getSpriteButton
CCMenuItemSprite* CCLayerParent::getSpriteButton(int tag,int price,const char* frameName,SEL_MenuHandler selector)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
CCMenuItemSprite *quirkButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("spawn.png"),CCSprite::createWithSpriteFrameName("spawn_sel.png"),this,selector);
CCSize contentSize = quirkButton->getContentSize();
//quirkButton->setPosition (ccp(contentSize.width* tag, contentSize.height/2));
quirkButton->setTag(tag);
CCSprite* quirk = CCSprite::createWithSpriteFrameName(frameName);
quirk->setPosition(ccp(quirk->getContentSize().width/2, contentSize.height-quirk->getContentSize().height/2));
quirkButton->addChild(quirk);
char temp[64];
sprintf(temp, "%d", price);
//CCLabel* quirkLabel = CCLabelBMFont::create(temp,"Courier_green.fnt");
CCLabelTTF* quirkLabel = CCLabelTTF::create(temp, "Helvetica-Bold", fontSizeBig, ccp(xMARGIN,yMARGIN), kCCTextAlignmentCenter );
quirkLabel->setColor(ccc3(255,255,255));
quirkLabel->setPosition(ccp(quirk->getContentSize().width/2, yMARGIN*0.4));
quirkButton->addChild(quirkLabel);
quirkButton->setZOrder(3);
return quirkButton;
}
示例10: init
bool StageMapLayer::init()
{
if(!CCLayer::init())
return false;
this->ignoreAnchorPointForPosition(false);
this->setAnchorPoint(AnchorPointLeftBottom);
this->setTouchEnabled(true);
this->setTouchMode(kCCTouchesOneByOne);
const CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// Background
m_Background = CCSprite::createWithSpriteFrameName("mainscene_background.png");
m_Background->retain();
m_Background->cocos2d::CCNode::setPosition(winSize.width / 2, winSize.height / 2);
for(int i=0; i<5; ++i)
{
CCString* fileName = CCString::createWithFormat("mainscene_cloud%d.png", i+1);
m_BackgroundCloud[i] = CCSprite::createWithSpriteFrameName(fileName->getCString());
m_BackgroundCloud[i]->retain();
m_Background->addChild(m_BackgroundCloud[i]);
CCPoint initialPosition = CCPointMake(RandomNumberGenerator::Int(0, static_cast<INT>(winSize.width)), RandomNumberGenerator::Int(30.f, INT(winSize.height*0.9f)));
m_BackgroundCloud[i]->setPosition(initialPosition);
// Cloud Moving Animation
const CCSize cloudSize = m_BackgroundCloud[i]->getContentSize();
const float speed = 5+ static_cast<float>(RandomNumberGenerator::Int(0, 25)); // pixel/sec
const float timeToLeftEnd = (initialPosition.x+cloudSize.width*0.5f)/speed;
const float timeToRepeatLeft = (winSize.width+cloudSize.width)/speed;
CCSprite* cloudNode = m_BackgroundCloud[i];
CCMoveTo* moveToLeftEnd = CCMoveTo::create(timeToLeftEnd, ccp(-cloudSize.width*0.5f, initialPosition.y));
CCCallFuncL* moveToRightEnd = CCCallFuncL::create([winSize, cloudNode, cloudSize, initialPosition]()
{
if( cloudNode )
{
cloudNode->setPosition(ccp(winSize.width+cloudSize.width*0.5f,initialPosition.y));
}
});
CCMoveTo* moveToLeftEndRepeat = CCMoveTo::create(timeToRepeatLeft, ccp(-cloudSize.width*0.5f, initialPosition.y));
CCSequence* moveToRightAndLeftEnd = CCSequence::create(moveToRightEnd, moveToLeftEndRepeat, nullptr);
CCRepeat* moveToRightAndLeftEndRepeat = CCRepeat::create(moveToRightAndLeftEnd, 20);
CCSequence* moveSeq = CCSequence::create(moveToLeftEnd, moveToRightAndLeftEndRepeat, nullptr);
cloudNode->runAction(moveSeq);
// End Cloud Moving Animation
}
m_Top = CCSprite::createWithSpriteFrameName("mainscene_top.png");
m_Top->retain();
const CCSize topSpriteSize = m_Top->getContentSize();
m_Top->setPosition(ccp(winSize.width*0.5f, winSize.height-topSpriteSize.height*0.5f));
m_Bottom = CCSprite::createWithSpriteFrameName("mainscene_bottom.png");
m_Bottom->retain();
const CCSize bottomSpriteSize = m_Bottom->getContentSize();
m_Bottom->setPosition(ccp(winSize.width*0.5f, bottomSpriteSize.height*0.5f));
//End Background
this->addChild(m_Background, StageMapLayerDepth_Background);
this->addChild(m_Top, StageMapLayerDepth_UIComponents);
this->addChild(m_Bottom, StageMapLayerDepth_UIComponents);
// Number Of Carrots
m_Carrot = CCSprite::createWithSpriteFrameName("mainscene_carrot_stat.png");
m_Carrot->retain();
const CCSize carrotSize = m_Carrot->getContentSize();
m_Carrot->setPosition(ccp( 5.f+carrotSize.width/2.f, winSize.height-carrotSize.height/2.f-5.f));
this->addChild(m_Carrot, StageMapLayerDepth_UIComponents);
m_Clover = CCSprite::createWithSpriteFrameName("mainscene_clover_stat.png");
m_Clover->retain();
const CCSize cloverSize = m_Clover->getContentSize();
m_Clover->setPosition(ccp( 5.f + carrotSize.width +10.f + cloverSize.width*0.5f, winSize.height-cloverSize.height*0.5f - 5.f));
this->addChild(m_Clover, StageMapLayerDepth_UIComponents);
User* myUser = GooRoomClient::Instance().GetUser();
if( myUser != nullptr )
{
m_NumberOfCarrots = CCLabelTTF::create(CCString::createWithFormat("%lld",myUser->GetGold())->getCString(), fontList[0].c_str(), 13);
m_NumberOfCarrots->retain();
m_NumberOfCarrots->setColor(ccBLACK);
const CCSize numberOfCarrotsSize = m_NumberOfCarrots->getContentSize();
m_NumberOfCarrots->setPosition(ccp(5.f+carrotSize.width*0.5f, m_Carrot->getPositionY()-2.f));
this->addChild(m_NumberOfCarrots, StageMapLayerDepth_UIComponents);
}
// END BASE
m_MapBase = CCNode::create();
m_MapBase->retain();
m_MapBase->setContentSize(winSize);
m_MapBase->setAnchorPoint(AnchorPointMidBottom);
m_MapBase->setPosition(ccp(winSize.width/2.f, 0.f));
this->addChild(m_MapBase,StageMapLayerDepth_MapBase);
m_StageInfoBox = CCSprite::createWithSpriteFrameName("stagemap_info_box.png");
m_StageInfoBox->retain();
//.........这里部分代码省略.........
示例11: onEnter
void CWaterpump::onEnter()
{
CCSprite::onEnter();
CCSize visiableView = CCDirector::sharedDirector()->getWinSize();
// 距离底部距离, 等同与怒气条的高度
float fBottomHeight = 65.0f;
// 监听玩家攻击
CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
callfuncO_selector(CWaterpump::onRoleAttackCallback),
MSG_ROLEACOMPLETE, NULL);
CCSprite *pumpBg = CCSprite::create("UI_01_01.png");
addChild(pumpBg);
pumpBg->setPosition(ccp(visiableView.width/2, pumpBg->getContentSize().height/2));
this->setContentSize(pumpBg->getContentSize());
// 灌水彩色图
CCProgressTo *to1 = CCProgressTo::create(3, 100);
m_pPump = CCProgressTimer::create(CCSprite::create("UI_01_04.png"));
m_pPump->setAnchorPoint(ccp(0.5f, 0.0f));
m_pPump->setType(kCCProgressTimerTypeBar);
m_pPump->setMidpoint(ccp(0,0));
m_pPump->setBarChangeRate(ccp(0, 1));
m_pPump->setPosition(ccp(visiableView.width/2 + 1, fBottomHeight));
m_pPump->runAction(CCRepeatForever::create(to1));
addChild(m_pPump);
// 指示针
m_pIndicator = CCSprite::create("UI_01_05.png");
m_pIndicator->setAnchorPoint(ccp(0.5f, 0.0f));
m_pIndicator->setPosition(ccp(visiableView.width/2, fBottomHeight));
addChild(m_pIndicator);
// 怒气值
m_pFuryPower = CCSprite::create("UI_01_03.png", CCRectMake(0,0,1090,44));
m_pFuryPower->setAnchorPoint(ccp(0.0f, 0.5f));
ccTexParams params = {GL_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE};
m_pFuryPower->getTexture()->setTexParameters(¶ms);
m_pFuryPower->setPosition(ccp(visiableView.width/2 - 545, 44));
m_pFuryPower->setScaleX(0.0f);
addChild(m_pFuryPower, -1);
CCSprite *pFuryBg = CCSprite::create("UI_01_02.png", CCRectMake(0,0,1090,44));
pFuryBg->getTexture()->setTexParameters(¶ms);
pFuryBg->setPosition(ccp(visiableView.width/2, 44));
addChild(pFuryBg, -2);
//菜单
//普通斧子用来传递给角色数据, 不做显示用
m_pNormalAxeItem = initMenuItemWithFiles(ROLEID_NORMAXE, szItemNormal[0], szItemSelected[0], szItemDisable[0], menu_selector(CWaterpump::onSelectedMenuItem));
m_pNormalAxeItem->setVisible(false);
CCMenuItemSprite *pFireItem = initMenuItemWithFiles(ROLEID_FIREAXE, szItemNormal[0], szItemSelected[0], szItemDisable[0], menu_selector(CWaterpump::onSelectedMenuItem));
CCMenuItemSprite *pIceItem = initMenuItemWithFiles(ROLEID_ICEAXE, szItemNormal[1], szItemSelected[1], szItemDisable[1], menu_selector(CWaterpump::onSelectedMenuItem));
CCMenuItemSprite *pBaneItem = initMenuItemWithFiles(ROLEID_BANEAXE, szItemNormal[2], szItemSelected[2], szItemDisable[2], menu_selector(CWaterpump::onSelectedMenuItem));
CCMenuItemSprite *pWindItem = initMenuItemWithFiles(ROLEID_WINDAXE, szItemNormal[3], szItemSelected[3], szItemDisable[3], menu_selector(CWaterpump::onSelectedMenuItem));
CCMenu *pMenu = CCMenu::create(m_pNormalAxeItem, pFireItem, pIceItem, pBaneItem, pWindItem, NULL);
float fItemHeight = pFireItem->getContentSize().height;
float fItemWidth = pFireItem->getContentSize().width;
float fPumpWidth = m_pPump->getContentSize().width;
pFireItem->setPosition(ccp(visiableView.width/2 - fPumpWidth/2 - (1.5f*fItemWidth), fItemHeight/2));
pIceItem->setPosition(ccp(visiableView.width/2 - fPumpWidth/2 - (0.5f*fItemWidth), fItemHeight/2));
pBaneItem->setPosition(ccp(visiableView.width/2 + fPumpWidth/2 + (0.5f*fItemWidth), fItemHeight/2));
pWindItem->setPosition(ccp(visiableView.width/2 + fPumpWidth/2 + (1.5f*fItemWidth), fItemHeight/2));
pMenu->setPosition(ccp(0, fBottomHeight));
addChild(pMenu);
scheduleUpdate();
}
示例12: setDimensions
// on "init" you need to initialize your instance
bool S11PrepareRes::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
//每个项目都要创建的东西
_menu = CCMenu::create(NULL);
_menu->setPosition(CCPointZero);
this->addChild(_menu, 101);
titleString = "";
scriptMap=ScriptParser::paserScript("S11PrepareRes","leftTitle");//right_TableView_Map
//背景图
{
CCSprite * aSprite = CCSprite::create("s11Background.png");
aSprite->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2));
//CC_BREAK_IF(! aSprite);
this->addChild(aSprite,98);
aSprite ->getTexture()->setAntiAliasTexParameters();//抗锯齿
}
//控件
{
CCSprite * aSprite = CCSprite::create("s11NavBar.png");
aSprite->setAnchorPoint(ccp(0.0,1.0));
aSprite->setPosition(ccp(0,visibleSize.height-40));
this->addChild(aSprite,100);
}
{
CCLabelTTF * leftTitleLabel = CCLabelTTF::create(s11Str2_macro,s11FontName_macro,s11TitleFontSize_macro);
CCLabelTTF* pLabel = leftTitleLabel;
pLabel->setColor(ccWHITE);
pLabel->setPosition( s11Position3_macro(pLabel));
this->addChild(pLabel, 100);
}
titleLabel = CCLabelTTF::create(s11Str2_macro,s11FontName_macro,s11TitleFontSize_macro);
CCLabelTTF* pLabel = titleLabel;
pLabel->setColor(ccWHITE);
pLabel->setPosition( s11Position4_macro(pLabel));
this->addChild(pLabel, 100);
{
CCSprite * aSprite = CCSprite::create("pRecButton.png");
aSprite->setPosition(s11Position1_macro(aSprite));
this->addChild(aSprite,100);
CCSprite * aSprite1 = CCSprite::create("s11FullScreenIcon.png");
aSprite1->setPosition(s11Position1_macro(aItem));
this->addChild(aSprite1,100);
CCSprite * sprite1 = CCSprite::create();
CCSprite * sprite2 = CCSprite::create();
CCMenuItemSprite *aItem = CCMenuItemSprite::create(
sprite1,
sprite2,
this,
menu_selector(S11PrepareRes::menuCloseCallback));
aItem->setPosition(s11Position1_macro(aItem));
aItem->setContentSize(aSprite->getContentSize());
_menu ->addChild(aItem,100);
}
CCTableView * tableView = CCTableView::create(this, s11Size1_macro);
tableView->setAnchorPoint(ccp(0.0,0.0));
tableView->setDirection(kCCScrollViewDirectionVertical);
tableView->setPosition(s11Position8_macro(tableView));
tableView->setDelegate(this);
tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
this->addChild(tableView,99);
tableView->reloadData();
std::string aStr = ScriptParser::readScript("s11TableCellTxt1.txt");
S11PrepareRes::detailString = aStr;
rightDetailTex = CCLabelTTF::create(aStr.c_str(), "Helvetica", 30.0);
rightDetailTex->setColor(ccBLACK);
rightDetailTex-> setDimensions(s11Size2_macro);
rightDetailTex->setPosition(s11Position9_macro(label));
this->addChild(rightDetailTex,100);
//TabelBar
//.........这里部分代码省略.........
示例13: initPet
void PrepareLayer::initPet(int leftOrRight)
{
///**初始化已经出战的左边的宠物**///
int petId = -1;
for (int i =0;i !=6; ++i )
{
if (GameConfigData::initialGameData().getPetStateById(i) == "2")
{
if (GameConfigData::initialGameData().getPetPosById(i) == leftOrRight)
{
petId = i;
}
}
}
CCMenuItemSprite *petAddLeft = (CCMenuItemSprite *)m_menu->getChildByTag(100+4+leftOrRight);
if (petAddLeft->getChildByTag(1000))
{
petAddLeft->removeChildByTag(1000);
}
CCPoint leftPoint[6] = {petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(20*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),
petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0),petAddLeft->getContentSize()/2+ccp(30*gScaleX,0)};
float scale[6] = {0.4*PRE_SCALE,0.4*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE,0.5*PRE_SCALE};
CCSprite *sp = NULL;
if (petId != -1)
{
char petFile[48];
sprintf(petFile,"ui/petUI/pet%d_0.png",petId);
sp = CCSprite::create(petFile);
sp->setScale(scale[petId]);
if(leftOrRight ==0)
{
sp->setPosition(leftPoint[petId]);
m_leftPitId = petId;
}
else
{
sp->setPosition(leftPoint[petId]);
m_rightPetId =petId;
}
showHeroPet(leftOrRight,petId);
}
else
{
sp = CCSprite::create("ui/shared/plus.png");
sp->setPosition(petAddLeft->getContentSize()/2+ccp(20*gScaleX,0));
if(leftOrRight ==0)
{
if(this->getChildByTag(45456)!=NULL)
{
this->getChildByTag(45456)->setVisible(false);
}
}
else
{
if(this->getChildByTag(45457)!=NULL)
{
this->getChildByTag(45457)->setVisible(false);
}
}
}
petAddLeft->addChild(sp,1,1000);
}
示例14: init
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
CCLog(" HelloWorld init --->");
/*CCLog(" SCALE_FACTOR --->%f " , SCALE_FACTOR);*/
top_distance = SCALE_FACTOR * 16;
/*CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
pCloseItem->setPosition(ccpAdd(VisibleRect::rightBottom(),
ccp(-pCloseItem->getContentSize().width/2, pCloseItem->getContentSize().height/2)));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);*/
CCLabelTTF* pLabel = CCLabelTTF::create("hello cocos2d-x", "Arial", SCALE_FACTOR * 36 );
pLabel->setPosition(ccpAdd(VisibleRect::top(),ccp(0, -pLabel->getContentSize().height)));
this->addChild(pLabel, 1);
//载入主菜单的pic list
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("main_menu.plist", "main_menu.png");
//背景图片
CCSprite* pSprite = CCSprite::create("bg.jpg");
pSprite->setPosition(VisibleRect::center());
this->addChild(pSprite, 0);
//两片树叶
//树叶1
CCSprite* pSprite_leaf1 = CCSprite::createWithSpriteFrameName("leaf1.png");
pSprite_leaf1->setPosition( ccpAdd(VisibleRect::center(), ccp(0,pSprite_leaf1->getContentSize().height/2*3)) );
this->addChild(pSprite_leaf1);
pSprite_leaf1->setAnchorPoint(ccp(0.5f,0.0f)); //设置锚点为中下点
//不停摆动的动画
CCActionInterval* rotateAction1 = CCRotateBy::create(0.1f,25.0f);
CCActionInterval* rotateAction2 = CCRotateTo::create(0.1f, -25.0f);
CCDelayTime* sleep_rotate = CCDelayTime::create(4.0f);
pSprite_leaf1->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(rotateAction1, rotateAction2,rotateAction1, rotateAction2,sleep_rotate, NULL))));
//树叶2
CCSprite* pSprite_leaf2 = CCSprite::createWithSpriteFrameName("leaf2.png");
pSprite_leaf2->setPosition( ccpAdd(VisibleRect::center(), ccp(pSprite_leaf1->getContentSize().width,pSprite_leaf1->getContentSize().height/2*3)) );
this->addChild(pSprite_leaf2);
pSprite_leaf2->setAnchorPoint(ccp(0.5f,0.0f)); //设置锚点为中下点
CCDelayTime* sleep_rotate_2 = CCDelayTime::create(2.0f);
pSprite_leaf2->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(sleep_rotate_2,rotateAction1, rotateAction2,rotateAction1, rotateAction2,sleep_rotate_2, NULL))));
//小岛
CCSprite* pSprite_Island = CCSprite::create("island.png");
pSprite_Island->setPosition(VisibleRect::center());
this->addChild(pSprite_Island, 0);
//设置选项(左)
CCMenuItemSprite* pMenuItemSprite_small_left = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("small_item_normal.png"), CCSprite::createWithSpriteFrameName("small_item_pressed.png") , this, menu_selector(HelloWorld::menuCallback));
CCMenu* pSpriteMenu_small_left = CCMenu::create(pMenuItemSprite_small_left,NULL);
pSpriteMenu_small_left->setPosition( ccpAdd(VisibleRect::center(),ccp( - pSprite_Island->getContentSize().width / 2 ,- pSprite_Island->getContentSize().height/3)) );
this->addChild(pSpriteMenu_small_left ,1);
//帮助选项(右)
CCMenuItemSprite* pMenuItemSprite_small_right = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("small_item_normal.png"), CCSprite::createWithSpriteFrameName("small_item_pressed.png") , this,menu_selector(HelloWorld::menuCallback));
CCMenu* pSpriteMenu_small_right = CCMenu::create(pMenuItemSprite_small_right,NULL);
pSpriteMenu_small_right->setPosition( ccpAdd(VisibleRect::center(),ccp( pSprite_Island->getContentSize().width / 2 ,- pSprite_Island->getContentSize().height/3)) );
this->addChild(pSpriteMenu_small_right ,1);
//开始游戏选项
CCMenuItemSprite* pMenuItemSprite = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("start_normal.png"), CCSprite::createWithSpriteFrameName("start_pressed.png"), this,menu_selector(HelloWorld::menuCallback));
pMenuItemSprite->setTag(MENU_ID_START);
CCMenu* pSpriteMenu = CCMenu::create(pMenuItemSprite,NULL);
pSpriteMenu->setPosition( ccpAdd(VisibleRect::bottom(),ccp(0,pMenuItemSprite->getContentSize().height/2*3)) );
this->addChild(pSpriteMenu ,1);
//.........这里部分代码省略.........
示例15: init
KDbool CScrGame::init ( KDvoid )
{
if ( !CCLayer::init ( ) )
{
return KD_FALSE;
}
const CCSize& tWinSize = CCDirector::sharedDirector ( )->getWinSize ( );
m_uiDamaged = g_pResMgr->getSprite ( this, eIMG_Effect_Damaged );
m_uiDamaged->setPosition ( ccpMid ( tWinSize ) );
m_uiDamaged->setVisible ( KD_FALSE );
m_uiEmergency = g_pResMgr->getSprite ( this, eIMG_Effect_Low_HP );
m_uiEmergency->setPosition ( ccpMid ( tWinSize ) );
m_uiEmergency->setVisible ( KD_FALSE );
m_uiLayer = CCLayer::create ( );
this->addChild ( m_uiLayer );
m_uiEnergy = g_pResMgr->getProgress ( m_uiLayer, eIMG_Player_HP_Red );
{
const CCSize& tSize = m_uiEnergy->getContentSize ( );
m_uiEnergy->setPosition ( ccp ( tWinSize.cx - tSize.cx - 20, tWinSize.cy - tSize.cy / 2 - 20 ) );
m_uiEnergy->setAnchorPoint ( ccp ( 0, 0.5f ) );
m_uiEnergy->setType ( kCCProgressTimerTypeBar );
m_uiEnergy->setMidpoint ( ccp ( 1, 0 ) );
m_uiEnergy->setBarChangeRate ( ccp ( 1, 0 ) );
m_uiEnergy->setPercentage ( 100 );
CCLabelBMFont* uiLabel = g_pResMgr->getLabel ( m_uiEnergy, "H" );
uiLabel->setPosition ( ccp ( -uiLabel->getContentSize ( ).cx / 2 - 10, tSize.cy / 2 ) );
}
m_uiScore = g_pResMgr->getLabel ( m_uiLayer, "Score : 0" );
m_uiScore->setPosition ( ccp ( tWinSize.cx / 2 - 30, tWinSize.cy - m_uiScore->getContentSize ( ).cy ) );
m_uiMode = g_pResMgr->getLabel ( m_uiLayer, "Touch Mode " );
m_uiMode->setAnchorPoint ( ccp ( 0, 0.5f ) );
m_uiMode->setPosition ( ccp ( 150, tWinSize.cy - m_uiScore->getContentSize ( ).cy ) );
m_uiRader = g_pResMgr->getSprite ( m_uiLayer, eIMG_BTN_Pad_BG );
{
const CCSize& tSize = m_uiRader->getContentSize ( );
m_uiRader->setPosition ( ccp ( tSize.cx / 2 + 20 , tWinSize.cy - tSize.cy / 2 - 90 ) );
}
m_uiWeapon = g_pResMgr->getSprite ( m_uiLayer, eIMG_Icon_Weapons, 0 );
{
const CCSize& tSize = m_uiWeapon->getContentSize ( );
m_uiWeapon->setPosition ( ccp ( tWinSize.cx - tSize.cx / 2 - 20 , tWinSize.cy - tSize.cy / 2 - 60 ) );
}
CCMenuItemSprite* pPause = g_pResMgr->getMenuItemSprite
(
m_uiLayer, eIMG_BTN_Pause_Nor, ePath_Null, this, menu_selector ( CScrGame::onPause )
);
{
const CCSize& tSize = pPause->getContentSize ( );
pPause->setPosition ( ccp ( tSize.cx / 2 + 20, tWinSize.cy - tSize.cy / 2 - 20 ) );
}
CCMenuItemSprite* pMode = g_pResMgr->getMenuItemSprite
(
m_uiLayer, eIMG_BTN_Pause_Nor, ePath_Null, this, menu_selector ( CScrGame::onMode )
);
{
const CCSize& tSize = pMode->getContentSize ( );
pMode->setPosition ( ccp ( tSize.cx / 2 + 90, tWinSize.cy - tSize.cy / 2 - 20 ) );
}
for ( KDuint i = 0; i < 2; i++ )
{
CCSprite* uiBullet = g_pResMgr->getSprite ( m_uiLayer, eIMG_Bullet );
{
const CCSize& tSize = uiBullet->getContentSize ( );
uiBullet->setPosition ( ccp ( tWinSize.cx - tSize.cx / 2 - 20 , tWinSize.cy - tSize.cy / 2 - ( i == 0 ? 150 : 190 ) ) );
m_uiBulletNum[i] = g_pResMgr->getLabel ( uiBullet, " 6 x" );
m_uiBulletNum[i]->setPosition ( ccp ( - tSize.cx / 2, tSize.cy / 2 ) );
}
m_uiTarget[i][0] = g_pResMgr->getSprite( m_uiLayer, eIMG_Target_Out );
m_uiTarget[i][1] = g_pResMgr->getSprite( m_uiTarget[i][0], eIMG_Target_In );
m_uiTarget[i][0]->setPosition ( ccp ( tWinSize.cx / 2 + ( i == 0 ? -10 : 10 ), tWinSize.cy / 2 ) );
m_uiTarget[i][1]->setPosition ( ccpMid ( m_uiTarget[i][0]->getContentSize ( ) ) );
m_uiTarget[i][1]->setVisible ( KD_FALSE );
m_uiPad[i][0] = g_pResMgr->getSprite ( this, eIMG_BTN_Pad_BG );
m_uiPad[i][1] = g_pResMgr->getSprite ( m_uiPad[i][0], eIMG_BTN_Pad_Nor );
m_uiPad[i][2] = g_pResMgr->getSprite ( m_uiPad[i][0], eIMG_BTN_Pad_Sel );
{
const CCSize& tSize = m_uiPad[i][0]->getContentSize ( );
//.........这里部分代码省略.........