本文整理汇总了C++中CCSprite类的典型用法代码示例。如果您正苦于以下问题:C++ CCSprite类的具体用法?C++ CCSprite怎么用?C++ CCSprite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CCSprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setGroupName
GroupCustomization::GroupCustomization(int GameMode)
{
//set game mode
m_GameMode = GameMode;
//init colors
for(int i=0;i<4;i++)
{
setGroupName(i,NULL);
}
//set center of the screen
CCSize size = CCDirector::sharedDirector()->getWinSize();
x = size.width/2;
y = size.height/2;
CCSprite* background = CCSprite::spriteWithFile("GroupCustomization/background.png");
addChild(background,0);
background->setPosition(ccp(x,y));
KeyboardNotificationLayer* knlGroups[4];
switch (GameMode)
{
case GAMERS_3:
knlGroups[0] = new CurrentGroupLayer(ID_RED);
knlGroups[1] = new CurrentGroupLayer(ID_GREEN);
knlGroups[2] = new CurrentGroupLayer(ID_BLUE);
layers.addObject(knlGroups[0]);
layers.addObject(knlGroups[1]);
layers.addObject(knlGroups[2]);
knlGroups[0]->release();
knlGroups[1]->release();
knlGroups[2]->release();
break;
case GROUP_2:
knlGroups[0] = new CurrentGroupLayer(ID_RED);
knlGroups[1] = new CurrentGroupLayer(ID_GREEN);
layers.addObject(knlGroups[0]);
layers.addObject(knlGroups[1]);
knlGroups[0]->release();
knlGroups[1]->release();
break;
case GROUP_3:
knlGroups[0] = new CurrentGroupLayer(ID_RED);
knlGroups[1] = new CurrentGroupLayer(ID_GREEN);
knlGroups[2] = new CurrentGroupLayer(ID_BLUE);
layers.addObject(knlGroups[0]);
layers.addObject(knlGroups[1]);
layers.addObject(knlGroups[2]);
knlGroups[0]->release();
knlGroups[1]->release();
knlGroups[2]->release();
break;
case GROUP_4:
knlGroups[0] = new CurrentGroupLayer(ID_RED);
knlGroups[1] = new CurrentGroupLayer(ID_GREEN);
knlGroups[2] = new CurrentGroupLayer(ID_BLUE);
knlGroups[3] = new CurrentGroupLayer(ID_YELLOW);
layers.addObject(knlGroups[0]);
layers.addObject(knlGroups[1]);
layers.addObject(knlGroups[2]);
layers.addObject(knlGroups[3]);
knlGroups[0]->release();
knlGroups[1]->release();
knlGroups[2]->release();
knlGroups[3]->release();
break;
}
pScrollLayer = CCScrollLayer::layerWithLayers(&layers,0);
addChild(pScrollLayer);
pScrollLayer->setPosition(ccp(0,0));
setPageIndicator(pScrollLayer->currentScreen,pScrollLayer->totalScreens);
CCMenuItem* itm_back = CCMenuItemImage::itemFromNormalImage("GroupCustomization/back_normal.png","GroupCustomization/back_selected.png",this,menu_selector(GroupCustomization::itm_backCallback));
itm_back->setAnchorPoint(ccp(0,0));
itm_back->setPosition(ccp(10,10));
CCMenuItem* itm_start = CCMenuItemImage::itemFromNormalImage("GroupCustomization/start_normal.png","GroupCustomization/start_normal.png",this,menu_selector(GroupCustomization::itm_startCallback));
itm_start->setAnchorPoint(ccp(0,0));
itm_start->setPosition(ccp(size.width-195,10));
CCMenu* mn_GroupCustomization = CCMenu::menuWithItems(itm_back,itm_start,NULL);
addChild(mn_GroupCustomization,1);
mn_GroupCustomization->setPosition(ccp(0,0));
}
示例2: CCLog
bool QuestionContainerSprite::init()
{
if (CCSprite::init())
{
//Add label
CCLabelTTF* label = CCLabelTTF::labelWithString("Answer 1", "Arial", 12);
label->setTag(100);
//Add the background
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCSprite* corner = CCSprite::spriteWithFile("Images/bugs/corner.png");
int width = size.width * 0.9f - (corner->getContentSize().width * 2);
int height = size.height * 0.15f - (corner->getContentSize().height * 2);
CCLayerColor* layer = CCLayerColor::layerWithColorWidthHeight(ccc4(255, 255, 255, 255 * .75), width, height);
layer->setPosition(ccp(-width / 2, -height / 2));
//First button is blue,
//Second is red
//Used for testing - change later
static int a = 0;
if (a == 0)
label->setColor(ccBLUE);
else
{
CCLog("Color changed");
label->setColor(ccRED);
}
a++;
addChild(layer);
corner->setPosition(ccp(-(width / 2 + corner->getContentSize().width / 2), -(height / 2 + corner->getContentSize().height / 2)));
addChild(corner);
CCSprite* corner2 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner2->setPosition(ccp(-corner->getPosition().x, corner->getPosition().y));
corner2->setFlipX(true);
addChild(corner2);
CCSprite* corner3 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner3->setPosition(ccp(corner->getPosition().x, -corner->getPosition().y));
corner3->setFlipY(true);
addChild(corner3);
CCSprite* corner4 = CCSprite::spriteWithFile("Images/bugs/corner.png");
corner4->setPosition(ccp(corner2->getPosition().x, -corner2->getPosition().y));
corner4->setFlipX(true);
corner4->setFlipY(true);
addChild(corner4);
CCSprite* edge = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge->setScaleX(width);
edge->setPosition(ccp(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), corner->getPosition().y));
addChild(edge);
CCSprite* edge2 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge2->setScaleX(width);
edge2->setPosition(ccp(corner->getPosition().x + (corner->getContentSize().width / 2) + (width / 2), -corner->getPosition().y));
edge2->setFlipY(true);
addChild(edge2);
CCSprite* edge3 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge3->setRotation(90);
edge3->setScaleX(height);
edge3->setPosition(ccp(corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
addChild(edge3);
CCSprite* edge4 = CCSprite::spriteWithFile("Images/bugs/edge.png");
edge4->setRotation(270);
edge4->setScaleX(height);
edge4->setPosition(ccp(-corner->getPosition().x, corner->getPosition().y + (corner->getContentSize().height / 2) + (height / 2)));
addChild(edge4);
addChild(label);
return true;
}
return false;
}
示例3: addChild
void MailInfoListLayer::setSystemMail(Email mail)
{
//CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,-132,true);
ListMenu *menu = ListMenu::create();
menu->setPosition(CCPointZero);
menu->setAnchorPoint(CCPointZero);
menu->setContentSize(this->getContentSize());
addChild(menu);
m_mMenu = menu;
//m_mMenu->runAction(CCCallFuncND::create(this, callfuncND_selector(MailInfoListLayer::changeMenuPriority_callfuncND), (void*)(-133)));
m_eEmail = mail;
sortMail(mail);
int count = 0;
int height = m_nHeight;
int width = count * 100;
m_nWidth = width;
count = 0;
int side = 50;
int bWidth = 0;
int _width = 0;
int pos_x = 0;
for (map<string,string>::iterator iter = m_lThingsList.begin(); iter != m_lThingsList.end() ; iter ++)
{
CCSprite *cailiaoSpr = CCSprite::create("daoju_kuang_bg.png");
cailiaoSpr->setScale(0.7f);
bWidth = cailiaoSpr->getContentSize().width * cailiaoSpr->getScaleX();
cailiaoSpr->setPosition(ccp(count * bWidth + ( side * ( count * 2 + 1 ) ) + bWidth / 2 ,height - cailiaoSpr->getContentSize().height * cailiaoSpr->getScaleY() / 2 - 5));
addChild(cailiaoSpr);
CCSprite *daojuSpr = CCSprite::create(iter->first.c_str());
daojuSpr->setScale(0.7f);
bWidth = daojuSpr->getContentSize().width * cailiaoSpr->getScaleX();
daojuSpr->setPosition(ccp(cailiaoSpr->getContentSize().width / 2, cailiaoSpr->getContentSize().height / 2));
cailiaoSpr->addChild(daojuSpr);
CCLabelTTF *nameTTF = CCLabelTTF::create(iter->second.c_str(),fontStr_kaiti,25.0f);
nameTTF->setPosition(ccp(cailiaoSpr->getPositionX(),nameTTF->getContentSize().height / 2 + 5));
addChild(nameTTF);
nameTTF->setColor(ccWHITE);
_width += cailiaoSpr->getPositionX() - pos_x;
pos_x = cailiaoSpr->getPositionX();
count ++;
}
_width += bWidth / 2 + side;
for (vector<Flat_DuanzaoGroupZBInfo>::iterator iter = mail.equipVec.begin(); iter != mail.equipVec.end() ; iter ++)
{
CCLabelTTF *nameTTF = CCLabelTTF::create(iter->zhuangbei_name.c_str(),fontStr_kaiti,25.0f);
nameTTF->setPosition(ccp(count * bWidth + ( side * ( count * 2 + 1 ) ) + bWidth / 2 + nameTTF->getContentSize().height / 2 ,nameTTF->getContentSize().height / 2 + 20));
addChild(nameTTF);
nameTTF->setColor(ccWHITE);
//string nameTemp = CS::getItemName(iter->zb_group_id) + LFStrings::getValue("zhi") + LFStrings::getValue("suipian") + getStrByInt(iter->suipian_id);
string equipfile = iter->zhuangbei_pic;
equipfile = "minute_" + equipfile + ".png";
m_lThingsList.insert(map<string,string>::value_type(equipfile,iter->zhuangbei_name));
string diwenStr = ImageManager::getManager()->getImageData_DiWen_WithBianKuang(iter->zhuangbei_colour);
CCMenuItemImage *eqDiwenImg = CCMenuItemImage::create(diwenStr.c_str(), diwenStr.c_str(), this,
menu_selector(MailInfoListLayer::menuItemClicked_Equip));
m_mMenu->addChild(eqDiwenImg);
eqDiwenImg->setTag(iter->zb_group_id);
eqDiwenImg->setScale(0.8f);
bWidth = eqDiwenImg->getContentSize().width * eqDiwenImg->getScaleX();
eqDiwenImg->setPosition(ccp( nameTTF->getPositionX(),nameTTF->getPositionY() + nameTTF->getContentSize().height / 2 + eqDiwenImg->getContentSize().height / 2 + 5));
CCSprite *daojuSpr = CCSprite::create(equipfile.c_str());
daojuSpr->setScale(0.24f);
bWidth = daojuSpr->getContentSize().width * eqDiwenImg->getScaleX();
daojuSpr->setPosition(ccp(eqDiwenImg->getContentSize().width / 2, eqDiwenImg->getContentSize().height / 2));
eqDiwenImg->addChild(daojuSpr);
/*CCSprite *cailiaoSpr = CCSprite::create("daoju_kuang_bg.png");
cailiaoSpr->setScale(0.7f);
bWidth = cailiaoSpr->getContentSize().width * cailiaoSpr->getScaleX();
cailiaoSpr->setPosition(ccp(count * bWidth + ( side * ( count * 2 + 1 ) ) + bWidth / 2 ,height - cailiaoSpr->getContentSize().height * cailiaoSpr->getScaleY() / 2 - 5));
addChild(cailiaoSpr);*/
_width += eqDiwenImg->getPositionX() - pos_x;
pos_x = eqDiwenImg->getPositionX();
count ++;
}
_width += bWidth / 2 + side;
m_nWidth = _width;
this->setContentSize(CCSizeMake(m_nWidth,m_nHeight));
}
示例4: CCSizeMake
void IOSStoreLayer::showItemsNode()
{
int iTotalCount = 1;
int iPrice = 10;
int xcount = 1;
int ycount = 1;
CCSize size = CCSizeMake(120, 190);
if (m_bBaoxiangBuyTenTimes)
{
iTotalCount = 10;
size.width = 820;
size.height = 350;
xcount = 5;
ycount = 2;
iPrice = 95;
}
iTotalCount = this->getKaiBaoxiangRsqData().size();
if (iTotalCount >= 11)
{
xcount = 6;
}
if (iTotalCount == 2)
{
xcount = 2;
size = CCSizeMake(140*2, 190);
}
IOSStoreLayerScrollView* pView = IOSStoreLayerScrollView::createView(size, iTotalCount, xcount, ycount);
m_pGetItemNode->addChild(pView);
pView->ignoreAnchorPointForPosition(false);
pView->setAnchorPoint(ccp(0.5f, 0.5f));
pView->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2 - 60));
pView->setClickableCreater(pView);
pView->prepareToDisplay();
pView->setTouchEnabled(false);
pView->setTag(getitem_scrollview_tag);
//显示
CCSprite* pSmallbg = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_anniu_zaikaishici_fujia.png").c_str());
m_pGetItemNode->addChild(pSmallbg, 1);
pSmallbg->setPosition(ccp(200, 100));
//添加菜单
CCMenu* pMenu = CCMenu::create();
pMenu->setPosition(CCPointZero);
m_pGetItemNode->addChild(pMenu, 2);
//再开按钮
CCMenuItemImage* pItem = NULL;
int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore();
if (m_bBaoxiangBuyTenTimes)
{
pItem = CCMenuItemImage::create(
ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici.png").c_str(),
ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaishici_select.png").c_str(),
this, menu_selector(IOSStoreLayer::menuBtnCallBack));
pItem->setTag(buy_ten_again);
}
else
{
pItem = CCMenuItemImage::create(
ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici.png").c_str(),
ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_zaikaiyici_select.png").c_str(),
this, menu_selector(IOSStoreLayer::menuBtnCallBack));
pItem->setTag(buy_one_again);
}
pItem->setPosition(ccp(pSmallbg->getPositionX() + pSmallbg->getContentSize().width/2 + pItem->getContentSize().width/2 - 30,
pSmallbg->getPositionY()));
pMenu->addChild(pItem);
//星星数量
CCLabelAtlas* lable = CCLabelAtlas::create(
"0123456789",
ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"season_star_amount.png").c_str(),
30, 47,//24
'0');
m_pGetItemNode->addChild(lable, 1, star_count_str_tag);
lable->setAnchorPoint(ccp(0, 0.5));
lable->setScale(0.6f);
int iCount = 10;
if (m_bBaoxiangBuyTenTimes)
{
iCount = 95;
}
char charStarCount[10] = {};
sprintf(charStarCount, "%d", iCount);
lable->setString(charStarCount);
lable->setPosition(ccp(pItem->getPositionX()-pItem->getContentSize().width/2-lable->getContentSize().width/2 - 40, pSmallbg->getPositionY() - 3));
//右边星星图标
CCSprite* pXingxing = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_xiaogk+"YX_start.png").c_str());
m_pGetItemNode->addChild(pXingxing, 1);
pXingxing->setPosition(ccp(lable->getPositionX() - 30, pSmallbg->getPositionY()));
//星星数不够时,只显示确定按钮
//确定按钮
CCMenuItemImage* pOKItem = CCMenuItemImage::create(
//.........这里部分代码省略.........
示例5: CostomeKeyPadDelegae
// on "init" you need to initialize your instance
bool StartMenu::init()
{
//////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
// 添加Android的按键处理,这里加了全局代理
this->setKeypadEnabled(true);
CostomeKeyPadDelegae *keyDelegate = new CostomeKeyPadDelegae();
keyDelegate->autorelease();
CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(keyDelegate);
//////////////////
// 2. add main menu ,logo, loading, and ships
winSize = CCDirector::sharedDirector()->getWinSize();
CCSprite* sl = CCSprite::create(s_loading);
sl->setAnchorPoint(ccp(0, 0));
this->addChild(sl,0,1);
CCSprite* logo = CCSprite::create(s_logo);
logo->setAnchorPoint(ccp(0.5, 1));
logo->setPosition(ccp(winSize.width/2, winSize.height-50));
this->addChild(logo, 10, 1);
CCSprite* newGameNormal = CCSprite::create(s_menu, CCRectMake(0, 0, 126, 33));
CCSprite* newGameSelected = CCSprite::create(s_menu, CCRectMake(0, 33, 126, 33));
CCSprite* newGameDisabled = CCSprite::create(s_menu, CCRectMake(0, 33*2, 126, 33));
CCSprite* gameSettingNormal = CCSprite::create(s_menu, CCRectMake(126, 0, 126, 33));
CCSprite* gameSettingNSelected = CCSprite::create(s_menu, CCRectMake(126, 33, 126, 33));
CCSprite* gameSettingDesabled = CCSprite::create(s_menu, CCRectMake(126, 33*2, 126, 33));
CCSprite* aboutNormal = CCSprite::create(s_menu, CCRectMake(252, 0, 126, 33));
CCSprite* aboutSelected = CCSprite::create(s_menu, CCRectMake(252, 33, 126, 33));
CCSprite* aboutDesabled = CCSprite::create(s_menu, CCRectMake(252, 33*2, 126, 33));
CCMenuItemSprite* newGame = CCMenuItemSprite::create(newGameNormal, newGameSelected, newGameDisabled, this, menu_selector(StartMenu::flareEffect));
CCMenuItemSprite* gameSetting = CCMenuItemSprite::create(gameSettingNormal, gameSettingNSelected, gameSettingDesabled, this, menu_selector(StartMenu::menuCallback));
gameSetting->setTag(20);
CCMenuItemSprite* about = CCMenuItemSprite::create(aboutNormal, aboutSelected, aboutDesabled, this, menu_selector(StartMenu::menuCallback));
about->setTag(21);
// 最后一个参数要是NULL
CCMenu* menu = CCMenu::create(newGame, gameSetting, about, NULL);
menu->alignItemsVerticallyWithPadding(20);
this->addChild(menu, 1, 2);
menu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 80));
this->schedule(schedule_selector(StartMenu::update), 0.1);
// ships
CCTexture2D *textCache = CCTextureCache::sharedTextureCache()->addImage(s_ship01);
m_ship = CCSprite::createWithTexture(textCache, CCRectMake(0, 45, 60, 38));
this->addChild(m_ship, 0, 4);
CCPoint position = ccp(CCRANDOM_0_1() * winSize.width, 0);
m_ship->setPosition(position);
m_ship->runAction(CCMoveBy::create(2, ccp(CCRANDOM_0_1() * winSize.width, position.y + winSize.height + 100)));
if (Config::sharedConfig()->getAudioState()) {
SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.7);
SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_mainMainMusic, true);
}
return true;
}
示例6: ccp
bool PetsNestClass::init()
{
CCSize size = LcdAdapClass::sharedLCDADAP()->getWinSize();
CCArray* comArray = CCArray::create();
isShowPopUP = false;
layerNum = 2;
layerPosIndex = 1;
startTouchPos = ccp(0,0);
selEggState = PETS_EGG_STATE_TYPE_NONE;
selEggType = PETS_BREED_EGG_TYPE_NONE;
// HUDClass::sharedHUD()->setUserCookieNum(250);
// HUDClass::sharedHUD()->setUserMilkNum(250);
// HUDClass::sharedHUD()->setUserNestNum(2);
// HUDClass::sharedHUD()->setUserMedicineNum(2);
LcdAdapClass::sharedLCDADAP()->setAdaptorLayerSizeAndPos(this);
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsSNS-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsNest-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsEgg-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsIcon-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsTheme01-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsTheme02-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsTheme03-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsTheme06-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsWhale-hd.plist");
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/Pets/PetsTip-hd.plist");
gameBG = CCSprite::createWithSpriteFrameName("PetMainBG.png");
CCSize gameBGSize = gameBG->getContentSize();
LcdAdapClass::sharedLCDADAP()->setAdaptorNodePos(gameBG, ccp(size.width / 2, size.height / 2));
//gameBG->setPosition(ccp(size.width / 2, size.height / 2));
this->addChild(gameBG,1);
shareWBSprite = CCSprite::createWithSpriteFrameName("share_bg.png");
CCSize shareWBSize = shareWBSprite->getContentSize();
shareWBSprite->setPosition(ccp(gameBGSize.width / 2, gameBGSize.height + (shareWBSize.height)));
gameBG->addChild(shareWBSprite,0);
CCSprite* wbleftSprite = CCSprite::createWithSpriteFrameName("share_left.png");
wbleftSprite->setPosition(ccp(shareWBSize.width * 24.0/100.0, shareWBSize.height * 40/100.0));
shareWBSprite->addChild(wbleftSprite,1);
CCSprite* wbrightBG = CCSprite::createWithSpriteFrameName("share_right_CN.png");
wbrightBG->setPosition(ccp(shareWBSize.width * 65/100, shareWBSize.height * 40/100));
shareWBSprite->addChild(wbrightBG,1);
CCMenuItemImage* sinaWB = CCMenuItemImage::create("share_weibo_normal.png", "share_weibo_normal.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
sinaWB->setPosition(ccp(shareWBSize.width * 54/100, shareWBSize.height * 40/100));
sinaWB->setTag(PETS_MENU_ID_TYPE_WEIBO_SINA);
CCMenuItemImage* tcWB = CCMenuItemImage::create("share_tencent_normal.png", "share_tencent_pressed.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
tcWB->setPosition(ccp(shareWBSize.width * 74/100, shareWBSize.height * 40/100));
tcWB->setTag(PETS_MENU_ID_TYPE_WEIBO_TC);
CCMenuItemImage* closeWB = CCMenuItemImage::create("share_close_normal.png", "share_close_pressed.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
closeWB->setPosition(ccp(shareWBSize.width * 92/100, shareWBSize.height * 66/100));
closeWB->setTag(PETS_MENU_ID_TYPE_WEIBO_CLOSE);
CCMenu* wbmenu = CCMenu::create(sinaWB,tcWB,closeWB,NULL);
wbmenu->setPosition(CCPointZero);
shareWBSprite->addChild(wbmenu,10);
CCSprite* petToolBar = CCSprite::createWithSpriteFrameName("PetToolBar.png");
CCSize toolBarSize = petToolBar->getContentSize();
petToolBar->setPosition(ccp(gameBGSize.width / 2, gameBGSize.height * 93 / 100));
gameBG->addChild(petToolBar,1);
CCMenuItemImage* home = CCMenuItemImage::create("PetBack01.png", "PetBack02.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
home->setTag((int)PETS_MENU_ID_TYPE_HOME);
home->setPosition(ccp(toolBarSize.width * 5 /100, toolBarSize.height/ 2));
comArray->addObject(home);
CCMenuItemImage* weibo = CCMenuItemImage::create("PetMenu01.png", "PetMenu02.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
weibo->setTag((int)PETS_MENU_ID_TYPE_WEIBO);
weibo->setPosition(ccp(toolBarSize.width * 15 /100, toolBarSize.height/ 2));
comArray->addObject(weibo);
CCMenuItemImage* shop = CCMenuItemImage::create("PetShop01_CN.png", "PetShop02_CN.png", this, menu_selector(PetsNestClass::menuSelActionCallBack));
shop->setTag((int)PETS_MENU_ID_TYPE_SHOP);
shop->setPosition(ccp(toolBarSize.width * 88 /100, toolBarSize.height/ 2));
comArray->addObject(shop);
CCMenu* menu = CCMenu::createWithArray(comArray);
menu->setPosition(CCPointZero);
petToolBar->addChild(menu,1);
//.........这里部分代码省略.........
示例7: setTitle
bool ResultScene::init()
{
bool result = GradientLayer::init();
if (result) {
setTitle(MessageResultTitle);
CCSize windowSize = CCDirector::sharedDirector()->getWinSize();
GameEngine *engine = GameEngine::sharedEngine();
CCSprite *braveImage = CCSprite::createWithSpriteFrameName("brave.png");
braveImage->setRotation(90);
braveImage->setPosition(ccp(windowSize.width / 2, windowSize.height - kBraveImageMarginTop - braveImage->getContentSize().height / 2));
this->addChild(braveImage);
CCLabelTTF *messageLabel = CCLabelTTF::create(engine->getResultMessage(), DefaultFontName, FontSizeSmall);
messageLabel->setPosition(ccp(windowSize.width / 2 + kBraveMessageAdjustX, windowSize.height - kBraveMessageMarginTop));
messageLabel->setAnchorPoint(ccp(0.0, 0.0));
this->addChild(messageLabel);
float boxBottom = kCommandAreaHeight + kCommandAreaMarginTop + kCommandAreaMarginBottom;
CCDrawNode *boxNode = CCDrawNode::create();
CCPoint contentBox[] = {ccp(kBoxMarginHorizontal, windowSize.height - kBoxMarginTop),
ccp(windowSize.width - kBoxMarginHorizontal, windowSize.height - kBoxMarginTop),
ccp(windowSize.width - kBoxMarginHorizontal, boxBottom),
ccp(kBoxMarginHorizontal, boxBottom)};
boxNode->drawPolygon(contentBox, 4, kBoxFillColor, 1, kBoxBorderColor);
this->addChild(boxNode);
CCString *scoreText = CCString::createWithFormat("%s:%d", MessageScoreText, engine->getScore());
CCLabelTTF *scoreLabel = CCLabelTTF::create(scoreText->getCString(), DefaultFontName, FontSizeNormal);
scoreLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kScoreLabelMarginTop));
this->addChild(scoreLabel);
map<hiberlite::sqlid_t, int> *foundItems = engine->getFoundItems();
map<hiberlite::sqlid_t, int>::iterator foundItemsIterator = foundItems->begin();
vector<Item> *items = engine->getItems();
float itemImageAreaMarginLeft = windowSize.width / 2 - ((kNumberOfLineItems / 2 - 1) * (kItemImageSize + kItemImageMarginHorizontal)) - kItemImageMarginHorizontal / 2 - kItemImageSize / 2;
int sumFoundItems = 0;
int index = 0;
while (foundItemsIterator != foundItems->end()) {
hiberlite::sqlid_t itemID = (*foundItemsIterator).first;
Item item = items->at(itemID - 1);
int count = (*foundItemsIterator).second;
const char *imageFileName = item->image.c_str();
int posX = index % kNumberOfLineItems;
int posY = index / kNumberOfLineItems;
CCPoint imagePosition = ccp(itemImageAreaMarginLeft + (kItemImageSize + kItemImageMarginHorizontal) * posX,
windowSize.height - kItemImageAreaMarginTop - (kItemImageSize + kItemImageMarginVertical) * posY);
CCSprite *itemImage = CCSprite::createWithSpriteFrameName(imageFileName);
itemImage->setPosition(imagePosition);
this->addChild(itemImage);
sumFoundItems += count;
if (count > kItemCountMax) {
count = kItemCountMax;
}
CCString *countText = CCString::createWithFormat("%d", count);
CCLabelTTF *countLabel = CCLabelTTF::create(countText->getCString(), DefaultFontName, FontSizeSmall);
countLabel->setPosition(ccpAdd(imagePosition, ccp(0, -kItemImageSize / 2 - kItemImageCountLabelAdjustY)));
this->addChild(countLabel);
foundItemsIterator++;
index++;
}
CCString *itemCountText = CCString::createWithFormat("%s:%d", MessageNumberOfFoundItemsText, sumFoundItems);
CCLabelTTF *itemCountLabel = CCLabelTTF::create(itemCountText->getCString(), DefaultFontName, FontSizeNormal);
itemCountLabel->setPosition(ccp(windowSize.width / 2, windowSize.height - kItemCountLabelMarginTop));
this->addChild(itemCountLabel);
CCLayerColor *retryLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight);
CCLabelTTF *retryLabel = CCLabelTTF::create(MessageRetryButtonTitle, DefaultFontName, FontSizeNormal);
retryLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2));
retryLayer->addChild(retryLabel);
CCMenuItem *retryItem = CCMenuItemLabel::create(retryLayer,
GameEngine::sharedEngine(),
menu_selector(GameEngine::startNewGame));
CCLayerColor *backTitleLayer = CCLayerColor::create((ccColor4B){0x00, 0x00, 0x00, 0x00}, kCommandButtonWidth, kCommandButtonHeight);
CCLabelTTF *backTitleLabel = CCLabelTTF::create(MessageBackTitleButtonTitle, DefaultFontName, FontSizeNormal);
backTitleLabel->setPosition(ccp(kCommandButtonWidth / 2, kCommandButtonHeight / 2));
backTitleLayer->addChild(backTitleLabel);
CCMenuItem *backTitleItem = CCMenuItemLabel::create(backTitleLayer,
GameEngine::sharedEngine(),
menu_selector(GameEngine::showTitle));
CCMenu *menu = CCMenu::create(retryItem, backTitleItem, NULL);
menu->alignItemsHorizontallyWithPadding(kCommandButtonPadding);
menu->setPosition(ccp(windowSize.width / 2, kCommandAreaMarginBottom + kCommandAreaHeight / 2));
this->addChild(menu);
}
//.........这里部分代码省略.........
示例8: menu_selector
// on "init" you need to initialize your instance
bool Param::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
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(Param::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
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
/////////////////////////////
// 3. add your codes below...
// add a label shows "Hello World"
// create and initialize a label
CCSprite* pLabel = CCSprite::create("parametre.png");
// position the label on the center of the screen
pLabel->setPosition(ccp(0,
origin.y + visibleSize.height - pLabel->getContentSize().height *2));
CCMoveTo* paramToCenter = CCMoveTo::create(0.5,ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height *2));
pLabel->runAction(paramToCenter);
// add the label as a child to this layer
this->addChild(pLabel, 1);
// add "Param" splash screen"
CCSprite* pSprite = CCSprite::create("bg_param.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;
}
示例9: CCArray
bool RankingScene::init() {
CCSize size = CCDirector::sharedDirector()->getWinSize();
w = size.width;
h = size.height;
players = new CCArray();
CCSprite *background = CCSprite::create("BackGrounds/BackGround2.png");
background->setPosition(ccp(w/2, h/2));
this->addChild(background);
CCSprite *topLine = CCSprite::create("line.png");
topLine->setPosition(ccp(w/2, 602));
topLine->setOpacity(70);
this->addChild(topLine);
CCSprite *bottomLine = CCSprite::create("line.png");
bottomLine->setPosition(ccp(w/2, 248));
bottomLine->setOpacity(70);
this->addChild(bottomLine);
//-------------- menu getperesent ---------------
CCMenuItemImage *reward =
CCMenuItemImage::create("Present.png","PresentOnClicked.png",
this, menu_selector(RankingScene::reward));
reward->setPosition(ccp(w/5, h/8));
string playerName = GameManager::sharedGameManager()->getName();
if (playerName == "") reward->setVisible(false);
CCHttpRequest* request = new CCHttpRequest();
string ipAddr = GameManager::sharedGameManager()->getIpAddr();
request->setUrl((ipAddr+":3000/users.json").c_str());
request->setRequestType(CCHttpRequest::kHttpGet);
request->setResponseCallback(this, callfuncND_selector(RankingScene::onHttpRequestCompleted));
CCHttpClient::getInstance()->send(request);
request->release();
//create startMenuItem
CCMenuItemImage *playItem =
CCMenuItemImage::create("Buttons/StartButton.png", "Buttons/StartButtonOnClicked.png",
this, menu_selector(RankingScene::play));
playItem->setPosition(ccp(w/2, h/8 - 10));
//create bgmItem
CCMenuItemImage *bgmItem =
CCMenuItemImage::create("BgmOn.png", "BgmOn.png",
this, menu_selector(RankingScene::bgm));
bgmItem->setPosition(ccp(w*4/5, h/8));
CCMenu* pMenu = CCMenu::create(playItem, bgmItem, reward, NULL);
pMenu->setPosition(ccp(0,0));
this->addChild(pMenu);
bgm_off = CCSprite::create("BgmOff.png");
bgm_off->setPosition(bgmItem->getPosition());
bgm_off->setVisible(GameManager::sharedGameManager()->getBgm());
if (GameManager::sharedGameManager()->getBgm()) {
SimpleAudioEngine::sharedEngine()->setEffectsVolume(0.0f);
} else {
SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.0f);
}
this->addChild(bgm_off);
return true;
}
示例10: CC_BREAK_IF
// on "init" you need to initialize your instance
bool FC_Intro::init()
{
bool bRet = false;
do
{
this->setTouchEnabled(true);
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(255,255,255,255)));
s = CCDirector::sharedDirector()->getWinSize();
// m_nGameLevel = 0; // easy
m_nGameLevel = CCUserDefault::sharedUserDefault()->getIntegerForKey("FC_GAME_LEVEL", 0);
// 상단 타이틀 영역
CCSprite* pTitleBG = CCSprite::create("common/game/game_top_bg.png");
pTitleBG->setPosition(ccp(0, s.height));
pTitleBG->setAnchorPoint(ccp(0, 1.0f));
// addChild(pTitleBG, 3);
// Title 그리기
char* szLang = LanguageUtil::getLanguageCode();
char szTitle[260];
sprintf(szTitle, "common/game/flipCard/game_title_%s.png", szLang);
CCSprite* pTitle = CCSprite::create(szTitle);
pTitle->setPosition(ccp(s.width/2, s.height - pTitleBG->getContentSize().height/2));
this->addChild(pTitle, 4);
/*
// 배경 이미지 그리기
CCSprite* pBG = CCSprite::create("game/main_bg.png");
pBG->setAnchorPoint(ccp(0, 0));
pBG->setPosition(ccp(0, 0));
this->addChild(pBG, 2);
*/
// Main BG
CCSprite* pBack_base = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg_base.png"));
pBack_base->setAnchorPoint(ccp(0,0));
this->addChild( pBack_base );
CCSprite* pBack = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg.png"));
CCSprite* pBack1 = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg1.png"));
CCSprite* pBack2 = CCSprite::createWithTexture(CCTextureCache::sharedTextureCache()->addImage("Main/main_bg2.png"));
pBack->setAnchorPoint(ccp(0,0));
pBack1->setAnchorPoint(ccp(0,0));
pBack2->setAnchorPoint(ccp(0,0));
CCParallaxNode* voidNode = CCParallaxNode::create();
voidNode->addChild(pBack, 1, ccp(1.0f,0.0f), ccp(0,0));
voidNode->addChild(pBack1, 1, ccp(1.0f,0.0f), ccp(1874,0) );
voidNode->addChild(pBack2, 1, ccp(1.0f,0.0f), ccp(3748,0) );
CCActionInterval* go = CCMoveBy::create(200, ccp(-3748,0) );
CCActionInterval* goBack = go->reverse();
CCFiniteTimeAction* seq = CCSequence::create(go, goBack, NULL);
CCAction* act = CCRepeatForever::create( (CCActionInterval*) seq);
voidNode->runAction( act );
this->addChild( voidNode );
// Guide Image
CCSprite* pIntro = CCSprite::create("game/flipCard/main_img_bg.png");
pIntro->setPosition(ccp(s.width/2, GUIDE_BG_MARGIN_B));
pIntro->setAnchorPoint(ccp(0.5f, 0));
this->addChild(pIntro, 3);
// Guide Text
char szGuide[260];
sprintf(szGuide, "common/game/flipCard/guide_text_%s.png", szLang);
CCSprite* pGuide = CCSprite::create(szGuide);
pGuide->setPosition(GUIDE_TEXT_XY);
pGuide->setAnchorPoint(ccp(0, 0.5f));
this->addChild(pGuide, 3);
// 난이도, 뒤로가기 버튼 표시
CreateMenu();
bRet = true;
} while (0);
return bRet;
}
示例11: GetSprite
bool CSInventory::init() {
if(!CCNode::init()) {
return false;
}
this->setContentSize(CCSize(320.0f, 80.0f * (float)INDEX_Y_MAX));
this->setAnchorPoint(ccp(0, 0));
this->setPosition(ccp(0.0f, 44.0f));
this->schedule(schedule_selector(CSInventory::update));
this->mIndex = INDEX_IS_NOT_SELECTED;
CCSprite* sprite = GetSprite(IMAGE_SETTING_SCENE::RESOURCE_IMAGE[IMAGE_SETTING_SCENE::IMG_INVENTORY_ITEM]);
sprite->setPosition(ccp(120.0f, 320.0f - 40.0f + 1.0f));
this->addChild(sprite);
sprite = GetSprite(IMAGE_SETTING_SCENE::RESOURCE_IMAGE[IMAGE_SETTING_SCENE::IMG_WASTEBASKET_CLOSE]);
sprite->setPosition(ccp(240.0f + 40.0f, 320.0f - 40.0f));
sprite->setTag(TAG_WASTEBASKET);
this->addChild(sprite);
for(int i = 0; i < INDEX_MAX; ++i) {
if(i < 3) {
this->mItem[i] = INDEX_IS_NOT_SELECTED;
}
this->mInventory[i] = INDEX_IS_NOT_SELECTED;
sprite = GetSprite(IMAGE_SETTING_SCENE::RESOURCE_IMAGE[IMAGE_SETTING_SCENE::IMG_INVENTORY_BASIC]);
sprite->setPosition(ccp((80 * (i%4 + 1) - 40.0f), 240.0f - 40.0f - (80 * (i/4))));
this->addChild(sprite);
}
// ITEM_TEST_1
ITEM table = ITEM(IMAGE_SETTING_SCENE::RESOURCE_IMAGE[IMAGE_SETTING_SCENE::IMG_ITEM_ENCHANT_1], "", 0, 0, 1, ITEM_ENCHANT);
this->mContainer.insert(pair<int, ITEM>(ITEM_TEST_1, table));
//Add Sprite
sprite = GetSprite(table.mSpriteName);
sprite->setTag(ITEM_TEST_1);
sprite->setPosition(ccp((80 * (0 + 1) - 40.0f), 240.0f - 40.0f - (80 * (0/4))));
this->addChild(sprite);
this->mInventory[0] = ITEM_TEST_1;
CCLabelTTF* label = CCLabelTTF::create("+ 10~30%", "Munro Small", 18);
label->setPosition(ccp((80 * (0 + 1) - 40.0f), 240.0f - 40.0f - (80 * (0/4))));
this->addChild(label);
// ITEM_TEST_2
table = ITEM(IMAGE_SETTING_SCENE::RESOURCE_IMAGE[IMAGE_SETTING_SCENE::IMG_ITEM_HELMET_1], "", 0, 0, 1, ITEM_HELMET);
this->mContainer.insert(pair<int, ITEM>(ITEM_TEST_2, table));
//Add Sprite
sprite = GetSprite(table.mSpriteName);
sprite->setTag(ITEM_TEST_2);
sprite->setPosition(ccp((80 * (1 + 1) - 40.0f), 240.0f - 40.0f - (80 * (1/4))));
this->addChild(sprite);
this->mInventory[1] = ITEM_TEST_2;
return true;
}
示例12: switch
void GetPeanuts::BuildMenu()
{
float scale = ScreenHelper::getTextureScale();
float scaleX = ScreenHelper::getTextureScaleX();
float scaleY = ScreenHelper::getTextureScaleY();
CCMenu *screenMenu = CCMenu::create();
CCSize dim;
dim.width = 200.0f;
dim.height = 35.0f;
for(int i = 0; i < 4; i++)
{
CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png","ctm_Store_LitStrip.png",this,menu_selector(GetPeanuts::buyButtonTapped) );
CCSprite *sprite = NULL;
switch(i)
{
case 0:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_A.png");
break;
case 1:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_B.png");
break;
case 2:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_C.png");
break;
case 3:
sprite = CCSprite::createWithSpriteFrameName("ctm_PeanutGraphic_D.png");
break;
}
sprite->setPosition(ccp(312/2-16,33));
temp->addChild(sprite);
const char *amount;
const char *cost;
switch(i)
{
case 0:
amount = "3,000";
cost = "$1.99";
break;
case 1:
amount = "35,000";
cost = "$7.99";
break;
case 2:
amount = "100,000";
cost = "$14.99";
break;
case 3:
amount = "300,000";
cost = "$24.99";
break;
}
CCLabelTTF *label = CCLabelTTF::create(amount,"Jacoby ICG Black.ttf",30,dim,kCCTextAlignmentRight);
label->setColor(ccc3(237,188,0));
label->setPosition(ccp(200,46));
temp->addChild(label);
CCSize dim;
dim.width = 70.0f;
dim.height = 20.0f;
label = CCLabelTTF::create(cost,"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentRight);
label->setColor(ccc3(230,230,230));
label->setPosition(ccp(260,23));
temp->addChild(label);
temp->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,-250.0f,-i*50));
temp->setScale(scale);
screenMenu->addChild(temp);
m_MenuItems[i] = temp;
}
screenMenu->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_CENTER,86,-119));
addChild(screenMenu);
}
示例13: switch
//implementation CurrentGroupLayer
CurrentGroupLayer::CurrentGroupLayer(int idColor)
{
int color_index=0;
switch (idColor)
{
case ID_GREEN: color_index=1;break;
case ID_BLUE: color_index=2;break;
case ID_YELLOW: color_index=3;break;
}
const char* m_colors[] = {
"GroupCustomization/red.png",
"GroupCustomization/green.png",
"GroupCustomization/blue.png",
"GroupCustomization/yellow.png"
};
KeyboardNotificationLayer::onEnter();
//Coords of center screen
CCSize size = CCDirector::sharedDirector()->getWinSize();
x = size.width/2;
y = size.height/2;
//Color box
CCSprite* s_Color = CCSprite::spriteWithFile(m_colors[color_index]);
addChild(s_Color,1);
s_Color->setPosition(ccp(x+COLOR_POS_X,y+COLOR_POS_Y));
//white stripe
CCSprite* sStripe = CCSprite::spriteWithFile("GroupCustomization/stripe.png");
addChild(sStripe,0);
sStripe->setPosition(ccp(x,y-40));
sStripe->setOpacity(75);
//TextInput
m_nCharLimit = CHAR_LIMIT;
m_pTextFieldAction = CCRepeatForever::actionWithAction(
(CCActionInterval*)CCSequence::actions(
CCFadeOut::actionWithDuration(0.25),
CCFadeIn::actionWithDuration(0.25),
0
));
m_pTextFieldAction->retain();
m_bAction = false;
m_pTextField = CCTextFieldTTF::textFieldWithPlaceHolder("input u name",
FONT_NAME,
FONT_SIZE);
addChild(m_pTextField,1,ID_LABEL);
m_pTextField->setDelegate(this);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// on android, CCTextFieldTTF cannot auto adjust its position when soft-keyboard pop up
// so we had to set a higher position
m_pTextField->setPosition(ccp(x / 2, y/2 + 50));
#else
m_pTextField->setPosition(ccp(x,y-40)); //-150 Y
#endif
m_pTrackNode = m_pTextField;
}
示例14: CC_BREAK_IF
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
bool bRet = false;
do
{
//////////////////////////////////////////////////////////////////////////
// super init first
//////////////////////////////////////////////////////////////////////////
CC_BREAK_IF(! CCLayerColor::initWithColor( ccc4(255,255,255,255) ) );
//////////////////////////////////////////////////////////////////////////
// add your codes below...
//////////////////////////////////////////////////////////////////////////
// 1. Add a menu item with "X" image, which is clicked to quit the program.
// Create a "close" menu item with close icon, it's an auto release object.
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(HelloWorld::menuCloseCallback));
CC_BREAK_IF(! pCloseItem);
// Place the menu item bottom-right conner.
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2,
origin.y + pCloseItem->getContentSize().height/2));
// Create a menu with the "close" menu item, it's an auto release object.
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
CC_BREAK_IF(! pMenu);
// Add the menu to HelloWorld layer as a child layer.
this->addChild(pMenu, 1);
/////////////////////////////
// 2. add your codes below...
CCSprite *tree1 = CCSprite::create("tree.png");
tree1->setPosition( ccp(20,20) );
tree1->setAnchorPoint( ccp(0.5f, 0) );
tree1->setScale(1.5f);
this->addChild( tree1, 2, TAG_TREE_SPRITE_1);
CCSprite *cat = CCSprite::create("cheshire_cat.png");
cat->setPosition( ccp(250, 180) );
cat->setScale( 0.4f );
this->addChild( cat, 3, TAG_CAT_SPRITE);
//CCTexture2D
CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("tree.png");
CCSprite *tree2 = CCSprite::createWithTexture( texture );
tree2->setPosition( ccp(300, 20) );
tree2->setAnchorPoint( ccp(0.5f, 0) );
tree2->setScale(2.0f);
this->addChild( tree2, 2, TAG_TREE_SPRITE_2 );
//CCSpriteFrameCache
CCSpriteFrame *frame = CCSpriteFrame::createWithTexture( texture, tree2->getTextureRect() );
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame( frame, "tree.png");
CCSprite *tree3 = CCSprite::createWithSpriteFrameName("tree.png");
tree3->setPosition( ccp(400, 20) );
tree3->setAnchorPoint( ccp(0.5f, 0) );
tree3->setScale(1.5f);
this->addChild(tree3, 2, TAG_TREE_SPRITE_3);
// Load a set of sprite frames from PLIST file
CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
cache->addSpriteFramesWithFile("alice_scene_sheet.plist");
CCSprite *alice = CCSprite::createWithSpriteFrameName( "alice.png" );
alice->getTexture()->generateMipmap();
ccTexParams texParams = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE };
alice->getTexture()->setTexParameters( &texParams );
alice->setPosition( ccp(120,20) );
alice->setScale(0.4f);
alice->setAnchorPoint( ccp(0.5f, 0) );
this->addChild( alice, 2, TAG_ALICE_SPRITE);
CCSequence *alice_scale = CCSequence::create( CCScaleTo::create(4.0f, 0.7f), CCScaleTo::create(4.0f, 0.1f), NULL );
CCRepeatForever *repeat_alice_scale = CCRepeatForever::create( alice_scale );
alice->runAction( repeat_alice_scale );
CCSpriteBatchNode *cloudBatch = CCSpriteBatchNode::create("cloud_01.png", 10);
this->addChild( cloudBatch, 1, TAG_CLOUD_BATCH );
for(int x=0; x<10; x++) {
CCSprite *s= CCSprite::createWithTexture( cloudBatch->getTexture(), CCRectMake(0,0,64,64) );
s->setOpacity(100);
cloudBatch->addChild(s);
s->setPosition( ccp( getRandom(1, 0x7ffffff)%640-50, getRandom(1, 0x7ffffff)%150+200) );
}
//draw colored rectangles using a 1px x 1px white texture
CCSprite *sky = CCSprite::create("blank.png");
//.........这里部分代码省略.........
示例15: if
// Initialize our Main Menu Layer, and add the initial main menu with the title screen, play button and about button.
bool GameOverLayer::init()
{
// Initialize the parent
if (!CCLayer::init()) return false;
// Load the high scores
CCUserDefault *store = CCUserDefault::sharedUserDefault();
int bestScore = store->getIntegerForKey("best-score", 0);
int bestDistance = store->getIntegerForKey("best-distance", 0);
int bestDifficulty = store->getIntegerForKey("best-difficulty", 0);
bool newRecord = false;
if (GameManager::sharedGameManager()->getScore() > bestScore && GameManager::sharedGameManager()->getDistance() > bestDistance)
{
bestScore = GameManager::sharedGameManager()->getScore();
bestDistance = GameManager::sharedGameManager()->getDistance();
bestDifficulty = GameManager::sharedGameManager()->getDifficulty();
store->setIntegerForKey("best-score", bestScore);
store->setIntegerForKey("best-distance", bestDistance);
store->setIntegerForKey("best-difficulty", bestDifficulty);
store->flush();
newRecord = true;
}
// Set the screen size to the full dimensions of the device (full screen)
this->setContentSize(SCREEN_SIZE);
float labelScaleText = 1.2f;
if (GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid854x480 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x480 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid800x400 ||
GameManager::sharedGameManager()->getDeviceType() == kDeviceTypeAndroid720x480)
{
labelScaleText = 0.9f;
}
else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeNormal)
{
labelScaleText = 1.0f;
}
else if (GameManager::sharedGameManager()->getDeviceSize() == kDeviceSizeSmall)
{
labelScaleText = 0.5f;
}
CCSprite *gameOverTitle = CCSprite::createWithSpriteFrameName("game_over.png");
gameOverTitle->setScale(0.9f);
gameOverTitle->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.8));
this->addChild(gameOverTitle);
CCString *score = CCString::createWithFormat("YOUR SCORE: %i", GameManager::sharedGameManager()->getScore());
CCLabelBMFont *scoreLabel = CCLabelBMFont::create(score->getCString(), "myGlyphs.fnt");
scoreLabel->setScale(labelScaleText);
scoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.65));
this->addChild(scoreLabel);
CCString *distance = CCString::createWithFormat("YOUR DISTANCE: %i", GameManager::sharedGameManager()->getDistance());
CCLabelBMFont *distanceLabel = CCLabelBMFont::create(distance->getCString(), "myGlyphs.fnt");
distanceLabel->setScale(labelScaleText);
distanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.59));
this->addChild(distanceLabel);
CCString *ydifficulty;
switch (GameManager::sharedGameManager()->getDifficulty())
{
case 3:
ydifficulty = CCString::create("HARD");
break;
case 2:
ydifficulty = CCString::create("MEDIUM");
break;
default:
ydifficulty = CCString::create("EASY");
}
CCString *difficulty = CCString::createWithFormat("YOUR DIFFICULTY: %s", ydifficulty->getCString());
CCLabelBMFont *difficultyLabel = CCLabelBMFont::create(difficulty->getCString(), "myGlyphs.fnt");
difficultyLabel->setScale(labelScaleText);
difficultyLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.53));
this->addChild(difficultyLabel);
CCString *highScore = CCString::createWithFormat("HIGH SCORE: %i", bestScore);
CCLabelBMFont *highScoreLabel = CCLabelBMFont::create(highScore->getCString(), "myGlyphs.fnt");
highScoreLabel->setScale(labelScaleText);
highScoreLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.43));
this->addChild(highScoreLabel);
CCString *highDistance = CCString::createWithFormat("BEST DISTANCE: %i", bestDistance);
CCLabelBMFont *highDistanceLabel = CCLabelBMFont::create(highDistance->getCString(), "myGlyphs.fnt");
highDistanceLabel->setScale(labelScaleText);
highDistanceLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.37));
this->addChild(highDistanceLabel);
CCString *bdifficulty;
switch (bestDifficulty)
{
case 3:
bdifficulty = CCString::create("HARD");
break;
case 2:
//.........这里部分代码省略.........