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)); }
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; }
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)); }
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( ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi.png").c_str(), ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_anniu_quedingi_select.png").c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); pOKItem->setTag(ok_btn_tag); pOKItem->setPosition(ccp(this->getContentSize().width/2 + pOKItem->getContentSize().width, pSmallbg->getPositionY())); pMenu->addChild(pOKItem); if (iStarCount < iPrice) { lable->setVisible(false); pXingxing->setVisible(false); pSmallbg->setVisible(false); pItem->setVisible(false); pOKItem->setPosition(ccp(this->getContentSize().width/2, pSmallbg->getPositionY())); } pMenu->setTouchPriority(kCCMenuHandlerPriority-5); }
void IOSStoreLayer::initKaibaoxiangNode() { //获取要显示的所有道具的个数 if (m_iBaoxiangCellCount <= 0 ) { return; } //添加道具的tableview CCTableView* tableView = (CCTableView*)m_pKaibaoxiangNode->getChildByTag(kaibaoxiang_node_tableview_tag); if (tableView) { tableView->removeFromParent(); } tableView = CCTableView::create(this, CCSizeMake(230*m_iBaoxiangCellCount, 380)); // tableView->ignoreAnchorPointForPosition(false); // tableView->setAnchorPoint(ccp(0.5f, 0.5f)); tableView->setViewSize(CCSizeMake(920, 380)); tableView->setDirection(kCCScrollViewDirectionHorizontal); tableView->setPosition(ccp(35, 40)); // tableView->setPosition(ccp(m_pBg->getContentSize().width/2, m_pBg->getContentSize().height/2)); tableView->setDelegate(this); tableView->setTag(kaibaoxiang_node_tableview_tag); CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(tableView); if (m_iBaoxiangCellCount > 4) { tableView->runAction(CCSequence::create(CCDelayTime::create(0.01f), CCCallFuncN::create(this, callfuncN_selector(IOSStoreLayer::UpTableViewPrioority)), NULL)); } m_pKaibaoxiangNode->addChild(tableView, 2); tableView->reloadData(); if (m_iBaoxiangCellCount > 0 && m_iBaoxiangCellCount <= 2) { tableView->setViewSize(CCSizeMake(230*m_iBaoxiangCellCount, 380)); } if(m_iBaoxiangCellCount == 1) { tableView->setPosition(ccp(m_pBg->getContentSize().width/2 - 115, 40)); } else if (m_iBaoxiangCellCount == 2) { tableView->setPosition(ccp(m_pBg->getContentSize().width/2 - 220, 40)); } else if (m_iBaoxiangCellCount == 3) { tableView->setPosition(ccp(m_pBg->getContentSize().width/2 - 345, 40)); } //右边说明文字背景 CCSprite* pLeftBg = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_bg_2.png").c_str()); pLeftBg->setPosition(ccp(tableView->getPositionX() - pLeftBg->getContentSize().width/2, tableView->getPositionY()+pLeftBg->getContentSize().height/2)); m_pKaibaoxiangNode->addChild(pLeftBg); pLeftBg->setTag(leftbg_tag); //右边说明文字 CCLabelTTF* pLabel = CCLabelTTF::create("", fontStr_katong, 24, CCSize(180, 0), kCCTextAlignmentLeft); pLabel->setColor(fontColor_Store); pLabel->setPosition(ccp(pLeftBg->getContentSize().width/2, pLeftBg->getContentSize().height/2+10)); pLeftBg->addChild(pLabel, 1); pLabel->setTag(leftbg_string_tag); //下边说明文字背景 CCSprite* pDownBg = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_bg_3.png").c_str()); pDownBg->setPosition(ccp(pLeftBg->getContentSize().width/2, pLeftBg->getContentSize().height/2)); pLeftBg->addChild(pDownBg, 1, downbg_tag); CCLabelTTF* pDownLabel = CCLabelTTF::create("", fontStr_katong, 24, CCSize(200, 0), kCCTextAlignmentCenter); pDownLabel->setPosition(ccp(pDownBg->getPositionX()-3, 60)); pDownBg->addChild(pDownLabel, 1); pDownLabel->setTag(downbg_string_tag); if (m_enumComeFrom != from_SeasonSelector) { pDownBg->setVisible(false); pDownLabel->setVisible(false); } this->setComefrom(m_enumComeFrom); }
// 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; }
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); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "%d",HUDClass::sharedHUD()->getUserCookieNum()); userCookiNumLab = CCLabelAtlas::create(comBuffer, "Themes/Pets/PetNumBig.png", 13, 20, 46); userCookiNumLab->setPosition(ccp(toolBarSize.width * 32 / 100, toolBarSize.height * 45 /100)); petToolBar->addChild(userCookiNumLab,5); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "%d",HUDClass::sharedHUD()->getUserMilkNum()); userMilkNumLab = CCLabelAtlas::create(comBuffer, "Themes/Pets/PetNumBig.png", 13, 20, 46); userMilkNumLab->setPosition(ccp(toolBarSize.width * 49 / 100, toolBarSize.height * 45 /100)); petToolBar->addChild(userMilkNumLab,5); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "%d",HUDClass::sharedHUD()->getUserNestNum()); userNestNumLab = CCLabelAtlas::create(comBuffer, "Themes/Pets/PetNumBig.png", 13, 20, 46); userNestNumLab->setPosition(ccp(toolBarSize.width * 70 / 100, toolBarSize.height * 45 /100)); petToolBar->addChild(userNestNumLab,5); farmLayer = CCLayer::create(); farmLayer->setContentSize(ccp(size.width * layerNum, size.height)); farmLayer->setPosition(ccp(size.width * -1, 0)); this->addChild(farmLayer,5); petsEggArray = CCArray::create(); petsEggArray->retain(); this->initPetLayer(); this->initTipsBG(); return true; }
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); } return result; }
// 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; }
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; }
// 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; }
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; }
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); }
//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; }
// 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"); sky->setPosition( ccp(320, 240) ); sky->setTextureRect( CCRectMake(0,0,640,260) ); sky->setColor( ccc3(150, 200, 200) ); this->setTouchEnabled(true); this->addChild( sky, 0); // use updateGame instead of update, otherwise it will conflit with SelectorProtocol::update // see http://www.cocos2d-x.org/boards/6/topics/1478 //this->schedule( schedule_selector(HelloWorld::updateGame) ); //CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("background-music-aac.wav", true); bRet = true; } while (0); return bRet; }
// 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: bdifficulty = CCString::create("MEDIUM"); break; default: bdifficulty = CCString::create("EASY"); } CCString *highDifficulty = CCString::createWithFormat("DIFFICULTY: %s", bdifficulty->getCString()); CCLabelBMFont *highDifficultyLabel = CCLabelBMFont::create(highDifficulty->getCString(), "myGlyphs.fnt"); highDifficultyLabel->setScale(labelScaleText); highDifficultyLabel->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.31)); this->addChild(highDifficultyLabel); // Play again button createPlayAgainButton(); // Play Game Over Sound CocosDenshion::SimpleAudioEngine::sharedEngine()->setEffectsVolume(1.0f); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sfx_gameover.mp3", false); // Do new record animation if (newRecord) { // TODO } // Initialization was successful return true; }
void AdventureLevelClass::loadResAndInit() { CCSize size = LcdAdapClass::sharedLCDADAP()->getWinSize(); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/scene/stages_bg-hd.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Themes/scene/themescene1-hd.plist"); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "Themes/scene/stages_theme%d-hd.plist",GameStageConClass::sharedStageCon()->getGameStageIndex()); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(comBuffer); bgSprite = CCSprite::createWithSpriteFrameName("ss_bg.png"); CCSize bgSize = bgSprite->getContentSize(); // bgSprite->setPosition(ccp(size.width / 2, size.height / 2)); LcdAdapClass::sharedLCDADAP()->setAdaptorNodePos(bgSprite, ccp(size.width / 2, size.height / 2)); this->addChild(bgSprite,1); CCSprite* bgCN = CCSprite::createWithSpriteFrameName("ss_bg_CN.png"); bgCN->setPosition(ccp(bgSize.width/2, bgSize.height/2)); bgSprite->addChild(bgCN,1); if (GameStageConClass::sharedStageCon()->getGameStageIndex() != GAME_STAGE_TYPE_EXTRE) { memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "ss_towers_%02d.png",(curPageIndex + 1)); levelTowerTypeSP = CCSprite::createWithSpriteFrameName(comBuffer);//default levelTowerTypeSP->setPosition(ccp(bgSize.width/2, bgSize.height * 18/100)); bgSprite->addChild(levelTowerTypeSP,3); levelNumSP = CCSprite::createWithSpriteFrameName("ss_waves_10.png");//default levelNumSP->setPosition(ccp(bgSize.width/2, bgSize.height * 84/100)); bgSprite->addChild(levelNumSP,3); CCSprite* leftCloud = CCSprite::createWithSpriteFrameName("ss_cloud.png"); CCSize cloudSize = leftCloud->getContentSize(); leftCloud->setPosition(ccp(bgSize.width / 2, bgSize.height / 2)); bgSprite->addChild(leftCloud,5); } ccColor4B color; color.a = 125; color.b = 0; color.g = 0; color.r = 0; scrollLayer = CCLayer::create();//default pos is (0,0) scrollLayer->setContentSize(CCSize(size.width * levelNum / 2, size.height)); bgSprite->addChild(scrollLayer,15); for (int i = 0; i < levelNum; i++) { gameLevelInfoStruct levelInfo = HUDClass::sharedHUD()->getGameCurLevelInfo((GAME_STAGE_TYPE)(GameStageConClass::sharedStageCon()->getGameStageIndex()), (i + 1)); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "ss_map%02d.png",(i + 1)); CCSprite* sprite = CCSprite::createWithSpriteFrameName(comBuffer); CCSize spriteSize = sprite->getContentSize(); //sprite->setPosition(ccp(size.width / 2, size.height / 2)); memset(comBuffer, 0, sizeof(comBuffer)); sprintf(comBuffer, "%s","gainhonor_1.png");//这里要加个判断,判断用户的荣誉 CCSprite* honorSP = NULL; if (levelInfo.UserGained > 0 && levelInfo.UserGained < 4) { sprintf(comBuffer, "gainhonor_%d.png",levelInfo.UserGained); honorSP = CCSprite::createWithSpriteFrameName(comBuffer); honorSP->setVisible(true);//要不要显示 } else { honorSP = CCSprite::createWithSpriteFrameName(comBuffer); honorSP->setVisible(false);//要不要显示 } honorSP->setPosition(ccp(spriteSize.width * 84/100, spriteSize.height * 22/100)); sprite->addChild(honorSP,1); CCSprite* allClearSP = CCSprite::createWithSpriteFrameName("gainhonor_4.png"); if (!levelInfo.isClearAllObject) { allClearSP->setVisible(false); } allClearSP->setPosition(ccp(spriteSize.width * 60/100, spriteSize.height * 22/100)); sprite->addChild(allClearSP,1); levelNormalArray->addObject(sprite);//normal CCLayerColor* layer = CCLayerColor::create(color); layer->setContentSize(spriteSize); ccBlendFunc blend = {GL_DST_ALPHA, GL_SRC_ALPHA}; layer->setBlendFunc(blend); CCRenderTexture* rt = CCRenderTexture::create(spriteSize.width, spriteSize.height); sprite->setPosition(ccp(spriteSize.width/2, spriteSize.height/2)); rt->begin(); sprite->visit(); layer->visit(); rt->end(); CCSprite* levelShade = CCSprite::createWithTexture(rt->getSprite()->getTexture()); levelShade->setFlipY(true); levelShade->setPosition(ccp((bgSize.width/2) * (i + 1), bgSize.height / 2)); levelShadeArray->addObject(levelShade); sprite->setPosition(ccp((bgSize.width/2) * (i + 1), bgSize.height / 2)); sprite->setVisible(false); scrollLayer->addChild(levelShade,1); scrollLayer->addChild(sprite,1); if (i == curPageIndex) {//加个判断,哪一个关卡点亮 curShadeLevelSprite = levelShade; curNormalLevelSprite = sprite; curShadeLevelSprite->setVisible(false); curNormalLevelSprite->setVisible(true); } } gameStartMenu = CCMenuItemImage::create("ss_play_normal_CN.png", "ss_play_pressed_CN.png", this, menu_selector(AdventureLevelClass::selMenuCallBack)); if (GameStageConClass::sharedStageCon()->checkIsCurLevelLocked((curPageIndex + 1))) { gameStartMenu->setNormalSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ss_locked_CN.png")); gameStartMenu->setEnabled(false); } gameStartMenu->setTag(MENU_ID_START_TAG); gameStartMenu->setPosition(ccp(bgSize.width/2, bgSize.height * 8/ 100)); CCMenuItemImage* homeBtn = CCMenuItemImage::create("ss_back_normal.png", "ss_back_pressed.png", this, menu_selector(AdventureLevelClass::selMenuCallBack)); homeBtn->setTag(MENU_ID_HOME_TAG); homeBtn->setPosition(ccp(bgSize.width/25, bgSize.height * 95.5 / 100)); CCMenuItemImage* helpBtn = CCMenuItemImage::create("ss_help_normal.png", "ss_help_pressed.png", this, menu_selector(AdventureLevelClass::selMenuCallBack)); helpBtn->setTag(MENU_ID_HELP_TAG); helpBtn->setPosition(ccp(bgSize.width * 24/25, bgSize.height * 95.5 / 100)); CCMenu* menu = CCMenu::create(homeBtn,helpBtn,gameStartMenu,NULL); menu->setPosition(CCPointZero); bgSprite->addChild(menu,2); loadWaitSprite->removeFromParentAndCleanup(true); // this->gotoPageIndexNow(curPageIndex); scrollLayer->setPosition(ccp((bgSize.width/2) * (-curPageIndex), 0)); }
// on "init" you need to initialize your instance bool HelloWorld::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(HelloWorld::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 CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("Image/HelloWorld.png"); //pSprite->setScale(0.5); //pSprite->setAnchorPoint(ccp(0, 0)); // position the sprite on the center of the screen pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); //------------------------------ //--------CCMoveTo,CCMoveBy----- //------------------------------ //CCActionInterval* actionTo = CCMoveTo::create(2, ccp(0,0)); //CCActionInterval* actionBy = CCMoveBy::create(4, ccp(80, 80)); //pSprite->runAction(actionTo); //pSprite->runAction(CCMoveTo::create(1, ccp(100, 100))); //pSprite->runAction(CCSequence::create(actionTo, actionBy,NULL)); //------------------------------ //--------CCScaleTo,CCScaleBy--- //------------------------------ //CCActionInterval* scaleTo = CCScaleTo::create(2.0f, 0.5f,0.25f); //CCActionInterval* scaleBack = CCScaleTo::create(2.0f, 1.0f, 1.0f); //CCActionInterval* scaleBy = CCScaleBy::create(1, 1.0f,5.0f); //CCActionInterval* scaleBy2 = CCScaleBy::create(2, 5.0f, 1.0f); //pSprite->runAction(CCSequence::create(scaleTo, scaleBack, NULL)); //pSprite->runAction(scaleTo); //pSprite->runAction(scaleBack); //pSprite->runAction(scaleBy); //pSprite->runAction(CCSequence::create(scaleTo, scaleTo->reverse(), NULL)); //------------------------------ //--------CCSkewTo,CCSkewBy----- //------------------------------ //CCActionInterval* skewTo = CCSkewTo::create(2, 0, -135); //CCActionInterval* skewBy = CCSkewBy::create(2, -159, 0); //CCActionInterval* skewBy_reverse = skewBy->reverse(); //pSprite->runAction(skewTo); //pSprite->runAction(skewBy); //pSprite->runAction(CCSequence::create(skewBy, skewBy_reverse, NULL)); //------------------------------ //--------CCSkewTo,CCSkewBy----- //------------------------------ //CCRotateTo* rotateTo = CCRotateTo::create(2, 45.0f, -45.0f); //CCRotateTo* rotateTo_back = CCRotateTo::create(2, -45.0f, 45.0f); //CCRotateBy* rotateBy = CCRotateBy::create(2, 0.0f, 90.0f); //CCRotateBy* rotateBy_back = (CCRotateBy*)rotateBy->reverse(); //pSprite->runAction(rotateTo); //pSprite->runAction(rotateBy); //pSprite->runAction(CCSequence::create(rotateTo, rotateTo_back, NULL)); //pSprite->runAction(CCSequence::create(rotateBy, rotateBy_back, NULL)); //------------------------------ //-------- Skew Comparison----- //------------------------------ //pSprite->removeFromParentAndCleanup(true); //CCSize boxSize = CCSizeMake(100.0f, 100.0f); //CCLayerColor* box = CCLayerColor::create(ccc4(255, 255, 0, 255)); //box->setAnchorPoint(ccp(0.5,0.5)); //box->setContentSize(boxSize); //box->ignoreAnchorPointForPosition(false); //box->setPosition(ccp(visibleSize.width / 2, visibleSize.height - 100 - box->getContentSize().height / 2)); //this->addChild(box); //CCLabelTTF* label = CCLabelTTF::create("Standard cocos2d Skew", "Marker Felt", 16); //label->setPosition(ccp(visibleSize.width / 2, visibleSize.height - 100 + label->getContentSize().height)); //this->addChild(label); //CCSkewBy* actionTo = CCSkewBy::create(2, 360, 0); //CCSkewBy* actionToBack = CCSkewBy::create(2, -360, 0); //box->runAction(CCSequence::create(actionTo, actionToBack, NULL)); //------------------------------ //-------- Rotational Skew----- //------------------------------ //pSprite->removeFromParentAndCleanup(true); //CCSize boxSize = CCSizeMake(100.0f, 100.0f); //CCLayerColor* box = CCLayerColor::create(ccc4(255, 255, 0, 255)); //box->setAnchorPoint(ccp(0.5, 0.5)); //box->setContentSize(boxSize); //box->ignoreAnchorPointForPosition(false); //box->setPosition(ccp(visibleSize.width / 2, visibleSize.height - 100 - box->getContentSize().height / 2)); //this->addChild(box); //CCLabelTTF* label = CCLabelTTF::create("Rotational cocos2d Skew", "Marker Felt", 16); //label->setPosition(ccp(visibleSize.width / 2, visibleSize.height - 100 + label->getContentSize().height)); //this->addChild(label); //CCRotateBy* actionBy = CCRotateBy::create(2, 360, 0); //CCRotateBy* actionBy2 = CCRotateBy::create(2, -360, 0); //box->runAction(CCSequence::create(actionBy, actionBy2, NULL)); //------------------------------ //--------ActionSkewRotateScale- //------------------------------ //CCSize boxSize = CCSizeMake(100.0f, 100.0f); //CCLayerColor* box = CCLayerColor::create(ccc4(255, 255, 0, 255)); //box->setAnchorPoint(ccp(0, 0)); //box->setPosition(ccp(190, 110)); //box->setContentSize(boxSize); //static float markside = 10.0f; //CCLayerColor*uL = CCLayerColor::create(ccc4(255, 0, 0, 255)); //box->addChild(uL); //uL->setContentSize(CCSizeMake(markside, markside)); //uL->setPosition(ccp(0.0f, boxSize.height - markside)); //uL->setAnchorPoint(ccp(0, 0)); //CCLayerColor*uR = CCLayerColor::create(ccc4(0, 0, 255, 255)); //box->addChild(uR); //uR->setContentSize(CCSizeMake(markside, markside)); //uR->setPosition(ccp(boxSize.width - markside,boxSize.height-markside)); //uR->setAnchorPoint(ccp(0, 0)); //addChild(box); // //CCActionInterval* actionTo = CCSkewTo::create(2, 0.0f, 2.0f); //CCActionInterval* rotateTo = CCRotateTo::create(2, 0.0f, 15.0f); //CCActionInterval* actionScaleTo = CCScaleTo::create(2, 0.5f, -0.5f); // //CCActionInterval* actionScaleBack = CCScaleTo::create(2, 1.0f, 1.0f); //CCActionInterval* rotateToBack = CCRotateTo::create(2, 0); //CCActionInterval* actionToBack = CCSkewTo::create(2, 0, 0); //box->runAction(CCSequence::create(actionTo, actionToBack, NULL)); //box->runAction(CCSequence::create(rotateTo, rotateToBack, NULL)); //box->runAction(CCSequence::create(actionScaleTo, actionScaleBack, NULL)); //------------------------------------------------------------------ // // ActionRotate // //------------------------------------------------------------------ //CCActionInterval* actionTo = CCRotateTo::create(2, 45); //CCActionInterval* actionTo2 = CCRotateTo::create(2, -45); //CCActionInterval* actionT0 = CCRotateTo::create(2, 0); //pSprite->runAction(CCSequence::create(actionTo, actionT0, NULL)); //CCActionInterval* actionBy = CCRotateBy::create(2, 360); //CCActionInterval* actionByBack = actionBy->reverse(); //pSprite->runAction(CCSequence::create(actionBy, actionByBack, NULL)); //pSprite->runAction(CCSequence::create(actionTo2, actionT0->copy()->autorelease(), NULL)); //------------------------------------------------------------------ // // ActionJump // //------------------------------------------------------------------ //CCActionInterval* actionTo = CCJumpTo::create(2, ccp(300, 300), 50, 4); //CCActionInterval* actionUp = CCJumpBy::create(2, ccp(0, 0), 80, 4); //pSprite->runAction(CCRepeatForever::create(CCSequence::create(actionTo,actionUp,NULL))); //pSprite->runAction(actionUp); //------------------------------------------------------------------ // // ActionBezier // //------------------------------------------------------------------ //ccBezierConfig bezier; //bezier.controlPoint_1 = ccp(0, visibleSize.height / 2); //bezier.controlPoint_2 = ccp(300, -visibleSize.height / 2); //bezier.endPosition = ccp(300, 100); //CCActionInterval* bezierForward = CCBezierBy::create(3, bezier); //CCActionInterval* bezierBack = bezierForward->reverse(); //CCAction* rep = CCRepeatForever::create(CCSequence::create(bezierForward, bezierBack, NULL)); //pSprite->runAction(rep); //------------------------------------------------------------------ // // ActionBlink // //------------------------------------------------------------------ //CCActionInterval* action1 = CCBlink::create(2, 10); //pSprite->runAction(action1); //CCActionInterval* action2 = CCBlink::create(2, 100); //pSprite->runAction(action2); //------------------------------------------------------------------ // // ActionFade // //------------------------------------------------------------------ //CCActionInterval* action1 = CCFadeIn::create(5.0f); //CCActionInterval* action1_back = action1->reverse(); //CCActionInterval* action2 = CCFadeOut::create(1.0f); //CCActionInterval* action2_back = action2->reverse(); //pSprite->runAction(action1); //------------------------------------------------------------------ // // ActionTint // //------------------------------------------------------------------ //CCActionInterval* action1 = CCTintTo::create(2, 255, 200, 100); //CCActionInterval* action2 = CCTintBy::create(2, -255, -200, -100); //pSprite->runAction(action2); //------------------------------------------------------------------ // // ActionAnimate // //------------------------------------------------------------------ //CCAnimation* animation = CCAnimation::create(); //for (int i = 1; i < 15; i++) //{ // char szName[100] = { 0 }; // sprintf(szName, "Image/grossini_dance_%02d.png",i); // animation->addSpriteFrameWithFileName(szName); //} //animation->setDelayPerUnit(2.5f / 14.0f); //animation->setRestoreOriginalFrame(true); //CCAnimate* action = CCAnimate::create(animation); //CCSprite* grossini = CCSprite::create("Image/grossini.png"); //grossini->runAction(CCSequence::create(action, action->reverse(), NULL)); //grossini->setPosition(ccp(visibleSize.width *0.5 , visibleSize.height*0.5)); ////this->addChild(grossini, 0); ////File animation //CCAnimationCache* cache = CCAnimationCache::sharedAnimationCache(); //cache->addAnimationsWithFile("animation/animations-2.plist"); //CCAnimation* animation2 = cache->animationByName("dance_1"); //CCAnimate* action2 = CCAnimate::create(animation2); //CCSprite* sister = CCSprite::create("Image/grossinis_sister1.png"); //sister->runAction(CCSequence::create(action2, action2->reverse(), NULL)); //sister->setPosition(ccp(visibleSize.width *0.5 - 100, visibleSize.height*0.5)); //animation2->setLoops(4); //this->addChild(sister, 0); //------------------------------------------------------------------ // // ActionSequence // //------------------------------------------------------------------ //CCFiniteTimeAction* action = CCSequence::create(CCMoveBy::create(2, ccp(240, 0)), CCRotateBy::create(2, 540), NULL); //pSprite->runAction(action); //------------------------------------------------------------------ // // ActionSequence2 // //------------------------------------------------------------------ //CCFiniteTimeAction* action = CCSequence::create( //CCPlace::create(ccp(200, 200)), //CCShow::create(), //CCMoveBy::create(1, ccp(100, 0)), //CCCallFunc::create(this, callfunc_selector(XXX:callback1)) //); //------------------------------------------------------------------ // // ActionSpawn // //------------------------------------------------------------------ //CCAction* action = CCSpawn::create(CCJumpBy::create(2, ccp(300, 0), 50, 4), CCRotateBy::create(2, 720), NULL); //pSprite->setScale(0.5); //pSprite->runAction(action); //------------------------------------------------------------------ // // ActionRepeatForever // //------------------------------------------------------------------ //CCFiniteTimeAction* action = CCSequence::create( //CCDelayTime::create(1.5), //CCCallFuncN::create(this, callfuncN_selector(HelloWorld::repeatForever)), //NULL); //pSprite->runAction(action); //------------------------------------------------------------------ // // ActionRotateToRepeat // //------------------------------------------------------------------ //CCActionInterval* act1 = CCRotateTo::create(1, 90); //CCActionInterval* act2 = CCRotateTo::create(1, 0); //CCActionInterval* seq = CCSequence::create(act1, act2, NULL); //CCAction* rep1 = CCRepeatForever::create(seq); //CCActionInterval* rep2 = CCRepeat::create((CCFiniteTimeAction*)(seq->copy()->autorelease()), 10); //pSprite->runAction(rep1); //pSprite->runAction(rep2); //------------------------------------------------------------------ // // ActionRotateJerk // //------------------------------------------------------------------ //CCFiniteTimeAction * seq = CCSequence::create(CCRotateTo::create(0.5f, -20), CCRotateTo::create(0.5f, 20), NULL); //CCActionInterval* rep1 = CCRepeat::create(seq, 10); //CCAction* rep2 = CCRepeatForever::create((CCActionInterval*)(seq->copy()->autorelease())); //pSprite->runAction(rep1); //pSprite->runAction(rep2); //------------------------------------------------------------------ // // ActionRotateJerk // //------------------------------------------------------------------ //CCActionInterval* jump = CCJumpBy::create(2, ccp(300, 0), 100, 10); //CCFiniteTimeAction* action = CCSequence::create(jump, jump->reverse(), NULL); //pSprite->runAction(action); //this->addChild(pSprite, 0); return true; }
// on "init" you need to initialize your instance bool HelloWorld::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(HelloWorld::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 CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24); // position the label on the center of the screen pLabel->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - pLabel->getContentSize().height)); // add the label as a child to this layer this->addChild(pLabel, 1); // add "HelloWorld" splash screen" CCSprite* pSprite = CCSprite::create("HelloWorld.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); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true); m_BeginPoint = ccp(visibleSize.width/2, AREA_LIMIT); m_Rect.setRect(-(m_BeginPoint.x - AREA_LIMIT), -(m_BeginPoint.y - AREA_LIMIT), visibleSize.width - 2*AREA_LIMIT, visibleSize.height - 2*AREA_LIMIT); m_pBatchNode = CCSpriteBatchNode::create("test.png"); this->addChild(m_pBatchNode); m_pBatchNode->setPosition(m_BeginPoint); m_pBatchNode->setVisible(false); for (int i = 0; i < DOT_LENGTH; i++) { CCSprite* sprite = CCSprite::create("test.png"); m_pBatchNode->addChild(sprite); sprite->setPosition(ccp(0,i*DOT_SEGMENT)); m_vDot.push_back(sprite); } m_pBall = CCSprite::create(ball[0]); this->addChild(m_pBall); m_pBall->setPosition(m_BeginPoint); for (int i = 0; i < MONSTER_LENGTH; i++) { CCSprite* monsterSp = CCSprite::create(monster[i]); this->addChild(monsterSp); monsterSp->setPosition(ccp(200*i+200, 300)); CCLog("%f==%f",monsterSp->getContentSize().width,monsterSp->getContentSize().height); m_vMonster.push_back(monsterSp); } return true; }
void Architecture::addComponent(CCTexture2D* texture,float x,float y,int type,int zOrder,int bodyWidthDelta,int bodyHeightDelta) { CCSprite* spr = CCSprite::createWithTexture(texture); spr->setPosition(ccp(position.x-width*0.5+x,position.y-height*0.5+y)); target->addChild(spr,zOrder); ArchComponent* component = new ArchComponent(); component->setBodyWidthDelta(bodyWidthDelta); component->setBodyHeightDelta(bodyHeightDelta); component->setType(type); b2BodyDef bodyDef; float sprH = spr->getContentSize().height; float sprW = spr->getContentSize().width; bodyDef.type = b2_kinematicBody; bodyDef.position.Set( (position.x - width * 0.5 + x)/PTM_RATIO, (position.y - height * 0.5 + y)/PTM_RATIO ); //body Position Set. UserDataInBody* data = new UserDataInBody(); data->mChr = this; data->mSprite = spr; data->mType = TYPE_ARCHITECT; bodyDef.userData = data; //body에 텍스쳐 붙임. /* for(int i=0;i<components.size();i++) { if(y + sprH*0.5 > this->height) { height = sprH; break; } if(x + sprW*0.5 > this->width) { width = sprW; break; } } */ b2Body* body = world->CreateBody(&bodyDef); // body->SetAwake(false); // body->SetSleepingAllowed(false); b2FixtureDef fixtureDef; if(type == CIRCLE) { b2CircleShape circle; circle.m_radius = sprH*0.5/PTM_RATIO; fixtureDef.shape = &circle; fixtureDef.density = 1.0f; fixtureDef.friction= 0.2f; fixtureDef.restitution = 1.0f; fixtureDef.filter.categoryBits = CATEGORY_ARCHITECT; fixtureDef.filter.maskBits = CATEGORY_BULLET | CATEGORY_PLAYER; fixtureDef.density = 1.0f; body->CreateFixture(&fixtureDef); } else if(type == BOX) { b2PolygonShape box; box.SetAsBox((sprW-bodyWidthDelta)/PTM_RATIO*0.5,(sprH-bodyHeightDelta)/PTM_RATIO*0.5); fixtureDef.shape = &box; fixtureDef.density = 1.0f; fixtureDef.friction = 0.3f; fixtureDef.restitution = 0.0f; fixtureDef.filter.categoryBits = CATEGORY_ARCHITECT; fixtureDef.filter.maskBits = CATEGORY_BULLET | CATEGORY_PLAYER; fixtureDef.density = 1.0f; body->CreateFixture(&fixtureDef); } else if(type == POLYGON) { b2Vec2 vs2[4]; vs2[0].Set(-width*0.5/PTM_RATIO,-height*0.5/PTM_RATIO); vs2[1].Set(width*0.5/PTM_RATIO,-height*0.5/PTM_RATIO); vs2[2].Set(0/PTM_RATIO,(height*0.5)/PTM_RATIO); vs2[3].Set(-width*0.5/PTM_RATIO,-height*0.5/PTM_RATIO); b2ChainShape baseChain; baseChain.CreateChain(vs2,4); b2FixtureDef fixtureDef; fixtureDef.shape = &baseChain; fixtureDef.density = 1.0f; fixtureDef.friction = 1.0f; fixtureDef.filter.categoryBits = CATEGORY_ARCHITECT; fixtureDef.filter.maskBits = CATEGORY_BULLET | CATEGORY_PLAYER; body->CreateFixture(&fixtureDef); } else { CCLog("error Shape Type"); return; } component->setBody(body); component->setZOrder(zOrder); components.push_back(component); }
void MenuLayer::createScreen() { CCSprite * bg = CCSprite::create("bg.png"); bg->setPosition( ccp ( _screenSize.width*0.5 , _screenSize.height*0.5)); this->addChild( bg , kBackground ) ; /* CCSprite * logo = CCSprite::create("logo.png"); logo->setPosition( ccp ( logo->boundingBox().size.width * 0.5 , logo->boundingBox().size.height * 0.5 )) ; this->addChild( logo , kForeground ) ; */ CCSprite * logo = CCSprite::create("logo.png"); logo->setPosition( ccp ( _screenSize.width * 0.5 , _screenSize.height * 0.8 )) ; this->addChild( logo , kForeground ) ; //load Particle System /* _snow = CCParticleSystemQuad::create("snow.plist"); _snow->setPosition( ccp ( _screenSize.width*0.5 , _screenSize.height)) ; this->addChild( _snow , kBackground ) ; */ CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprite_sheet.plist"); _layerBatchNode = CCSpriteBatchNode::create("sprite_sheet.png" , 50 ); this->addChild( _layerBatchNode , kMiddleground ) ; CCSprite * menuItemOn ; CCSprite * menuItemOff ; menuItemOn = CCSprite::createWithSpriteFrameName("jieji_on.png"); menuItemOff = CCSprite::createWithSpriteFrameName("jieji_off.png"); CCMenuItemSprite * jiejiPlayItem = CCMenuItemSprite::create( menuItemOff , menuItemOn , this , menu_selector( MenuLayer::showJieji) ); menuItemOn = CCSprite::createWithSpriteFrameName("chan_on.png"); menuItemOff = CCSprite::createWithSpriteFrameName("chan_off.png"); CCMenuItemSprite * chanPlayItem = CCMenuItemSprite::create( menuItemOff , menuItemOn , this, menu_selector( MenuLayer::showChan )); /* menuItemOn = CCSprite::createWithSpriteFrameName("help_on.png"); menuItemOff = CCSprite::createWithSpriteFrameName("help_off.png"); CCMenuItemSprite * helpItem = CCMenuItemSprite::create( menuItemOff, menuItemOn, this, menu_selector(MenuLayer::showHelp)); */ menuItemOn = CCSprite::createWithSpriteFrameName("quitgame_on.png"); menuItemOff = CCSprite::createWithSpriteFrameName("quitgame_off.png"); CCMenuItemSprite * quitItem = CCMenuItemSprite::create( menuItemOff , menuItemOn , this , menu_selector(MenuLayer::quitGame)); _mainMenu = CCMenu::create( jiejiPlayItem , chanPlayItem , /*helpItem , */ quitItem ,NULL) ; _mainMenu->alignItemsVertically() ; _mainMenu->alignItemsVerticallyWithPadding(10); _mainMenu->setPosition( ccp ( _screenSize.width*0.5 , _screenSize.height*0.64 - logo->boundingBox().size.height )) ; this->addChild( _mainMenu , kForeground ) ; /* CCSprite * sprite = CCSprite::create("StopGameScreen.png") ; sprite->setPosition ( ccp( _screenSize.width * 0.5 , _screenSize.height * 0.5 )) ; this->addChild( sprite , kForeground ) ; CCLabelTTF * label = CCLabelTTF::create("Your Score","Marker Felt", sprite->boundingBox().size.height * 0.3 ) ; sprite->addChild( label , kForeground ) ; label->setAnchorPoint( ccp ( 0.5 , 0.5 )) ; label->setColor( ccc3 ( 0 , 0 , 0 )) ; label->setPosition( ccp( sprite->boundingBox().size.width * 0.5 , sprite->boundingBox().size.height - label->boundingBox().size.height * 0.6 ) ); CCLabelTTF * scoreDisplay = CCLabelTTF::create("0","Marker Felt", sprite->boundingBox().size.height * 0.3 ) ; scoreDisplay->setAnchorPoint( ccp ( 0.5 , 0.5 )) ; scoreDisplay->setColor( ccc3 ( 255 , 0 , 0 )) ; scoreDisplay->setPosition( ccp ( sprite->boundingBox().size.width * 0.5 , sprite->boundingBox().size.height - label->boundingBox().size.height * 1.4 )); sprite->addChild( scoreDisplay ) ; menuItemOn = CCSprite::create("Quit.png"); menuItemOff = CCSprite::create("Restart.png"); CCMenuItemSprite * quitJieji = CCMenuItemSprite::create( menuItemOff, menuItemOn, this, menu_selector(MenuLayer::showHelp)); menuItemOn = CCSprite::create("Restart.png"); menuItemOff = CCSprite::create("Quit.png"); CCMenuItemSprite * restartJieji = CCMenuItemSprite::create( menuItemOff, menuItemOn, this, menu_selector(MenuLayer::showHelp)); CCMenu * _jiejiGameOver = CCMenu::create( quitJieji , restartJieji , NULL ) ; _jiejiGameOver->alignItemsHorizontally() ; _jiejiGameOver->alignItemsHorizontallyWithPadding( 30 ) ; sprite->addChild( _jiejiGameOver , kForeground ) ; _jiejiGameOver->setPosition( ccp ( sprite->boundingBox().size.width* 0.5 , restartJieji->boundingBox().size.height )) ; */ /* CCSprite * sprite = CCSprite::createWithSpriteFrameName("PauseJieji.png") ; sprite->setPosition ( ccp( _screenSize.width * 0.5 , _screenSize.height * 0.5 )) ; this->addChild( sprite , kBackground ) ; */ /* CCMenuItemSprite * restartJieji = CCMenuItemSprite::create( menuItemOff, menuItemOn, this, menu_selector(MenuLayer::showHelp)); CCMenu * _jiejiGameOver = CCMenu::create( quitJieji , restartJieji , NULL ) ; _jiejiGameOver->alignItemsHorizontally() ; _jiejiGameOver->alignItemsHorizontallyWithPadding( 30 ) ; sprite->addChild( _jiejiGameOver , kForeground ) ; _jiejiGameOver->setPosition( ccp ( sprite->boundingBox().size.width* 0.5 , restartJieji->boundingBox().size.height )) ; */ /* CCSprite * sprite = CCSprite::createWithSpriteFrameName("PauseJieji.png") ; sprite->setPosition ( ccp( _screenSize.width * 0.5 , _screenSize.height * 0.5 )) ; this->addChild( sprite , kBackground ) ; */ }
// Initialize the GameScene bool GameScene::init() { // CCLog("GameScene::init"); bool bRet = false; do { coin50Platform = 12; coin100Platform = 15; coinJumpPlatform = 25; CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic("GameFieldMusic.mp3", true); target_Score = 10000; ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); // Initialize the parent - gets the sprite sheet loaded, sets the background and inits the clouds MainScene::init(); // Start off as game suspended gameSuspended = true; // Get the jumper sprite jumper = CCSprite::create("jumper_0.png"); this->addChild(jumper, 4, kjumper); CCArray * animArr = CCArray::create(); for (int i = 0 ; i < 16; i++) { CCString * tempString = CCString::createWithFormat("jumper_%d.png",i); CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(jumper->getPosition().x, jumper->getPosition().y, jumper->getContentSize().width, jumper->getContentSize().height)); animArr->addObject(tempFrame); } CCAnimation * jumpAnimation = CCAnimation::createWithSpriteFrames(animArr,0.1); jumpAnimate = CCAnimate::create(jumpAnimation); jumpAnimate->retain(); coin50Anim = CCArray::create(); coin100Anim = CCArray::create(); coinJumpAnim = CCArray::create(); CCSprite * coin1 = CCSprite::create("coin_1/coin50_1.png"); for (int i = 1;i < 20 ; i++) { CCString * tempString = CCString::createWithFormat("coin_1/coin50_%d.png",i); CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin1->getPosition().x, coin1->getPosition().y, coin1->getContentSize().width, coin1->getContentSize().height)); coin50Anim->addObject(tempFrame); } coin50Anim->retain(); CCSprite * coin2 = CCSprite::create("coin_2/coin100_1.png"); for (int i = 1;i < 20 ; i++) { CCString * tempString = CCString::createWithFormat("coin_2/coin100_%d.png",i); CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin2->getPosition().x, coin2->getPosition().y, coin2->getContentSize().width, coin2->getContentSize().height)); coin100Anim->addObject(tempFrame); } coin100Anim->retain(); CCSprite * coin3 = CCSprite::create("powerup/coinJump_1.png"); for (int i = 1;i < 20 ; i++) { CCString * tempString = CCString::createWithFormat("powerup/coinJump_%d.png",i); CCSpriteFrame * tempFrame = CCSpriteFrame::create(tempString->getCString(),CCRectMake(coin3->getPosition().x, coin3->getPosition().y, coin3->getContentSize().width, coin3->getContentSize().height)); coinJumpAnim->addObject(tempFrame); } coinJumpAnim->retain(); CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("fx-leafe.png"); particles = CCParticleFireworks::create(); particles->setTexture( texture ); particles->setLife(0.5); particles->setEmissionRate(100); particles->setPosVar(ccp(10,5)); particles->setSpeed(60); particles->setPosition(0, 0); particles->setAngle(90); particles->setAngleVar(270); particles->setStartSize(10.0); particles->setStartSizeVar(5); particles->setStartColor( ccc4f(1.0,1.0,1.0,1.0) ); particles->setEndColor(ccc4f(1.0,1.0,1.0,0.0) ); particles->setStartSpin(-90); particles->setStartSpinVar(30); particles->setEndSpin(-90); particles->setEndSpinVar(30); particles->setSpeedVar(30); particles->setPositionType( kCCPositionTypeGrouped ); this->addChild(particles, 10); particles_counter = 1; // Initialize the platforms for(int i=0; i<kNumCoines; i++) { CCSprite *bonus = CCSprite::create("coin_1/coin50_1.png"); this->addChild(bonus,4, kBonusStartTag+i); bonus->setScale(2.0); CCAnimation * coin50Animation = CCAnimation::createWithSpriteFrames(coin50Anim,0.03); CCAnimate * coin50Animate = CCAnimate::create(coin50Animation); bonus->runAction(CCRepeatForever::create(coin50Animate)); bonus->setVisible(false); bonus = NULL; } for(int i=0; i<kNumCoines; i++) { CCSprite *bonus = CCSprite::create("coin_2/coin100_1.png"); bonus->setScale(2.0); this->addChild(bonus,4, kBonusStartTag+i+30); CCAnimation * coin100Animation = CCAnimation::createWithSpriteFrames(coin100Anim,0.03); CCAnimate * coin100Animate = CCAnimate::create(coin100Animation); bonus->runAction(CCRepeatForever::create(coin100Animate)); bonus->setVisible(false); bonus = NULL; } for(int i=0; i<kNumCoines; i++) { CCSprite *bonus = CCSprite::create("powerup/coinJump_1.png"); this->addChild(bonus,4, kBonusStartTag+i+60); bonus->setScale(2.0); CCAnimation * coinJumpAnimation = CCAnimation::createWithSpriteFrames(coinJumpAnim,0.03); CCAnimate * coinJumpAnimate = CCAnimate::create(coinJumpAnimation); bonus->runAction(CCRepeatForever::create(coinJumpAnimate)); bonus->setVisible(false); bonus = NULL; } initPlatforms(); initTree(); // Create the bonus sprite // Load in the bonus images, 5, 10, 50, 100 // Create the Score Label CCLabelTTF* scoreLabel = CCLabelTTF::create("0", "Arial", 15.0); this->addChild(scoreLabel, 5, kScoreLabel); // Center the label scoreLabel->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width/2,CCDirector::sharedDirector()->getWinSize().height - 50)); // Start the GameScene stepping schedule(schedule_selector(GameScene::step)); // Enable the touch events setTouchEnabled(true); // Enable accelerometer events setAccelerometerEnabled(true); // Start the game startGame(); bRet = true; } while (0); return bRet; }
void IOSStoreLayer::initUI() { //初始化背景 m_pBg = CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_storelayerPath+"main_shangdian_bg.png").c_str()); this->addChild(m_pBg, 1, bg_tag); m_pBg->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2)); m_pKaibaoxiangNode = CCScale9Sprite::create(ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"nodebg.png").c_str()); m_pKaibaoxiangNode->ignoreAnchorPointForPosition(false); m_pKaibaoxiangNode->setAnchorPoint(ccp(0.5f, 0.5f)); m_pKaibaoxiangNode->setContentSize(m_pBg->getContentSize()); m_pKaibaoxiangNode->setPosition(ccp(m_pBg->getContentSize().width/2, m_pBg->getContentSize().height/2)); m_pBuyStarNode = CCScale9Sprite::create(ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"nodebg.png").c_str()); m_pBuyStarNode->ignoreAnchorPointForPosition(false); m_pBuyStarNode->setAnchorPoint(ccp(0.5f, 0.5f)); m_pBuyStarNode->setPosition(ccp(m_pBg->getContentSize().width/2, m_pBg->getContentSize().height/2)); m_pBuyStarNode->setContentSize(m_pBg->getContentSize()); m_pBg->addChild(m_pKaibaoxiangNode, 3, kaibaoxiang_node_tag); m_pBg->addChild(m_pBuyStarNode, 3, buystar_node_tag); m_pBgMenu = CCMenu::create(); m_pBgMenu->setPosition(CCPointZero); m_pBg->addChild(m_pBgMenu, 2); //左上角提示背景 CCSprite* pTip = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_tishi.png").c_str()); m_pBg->addChild(pTip, 0, tip_bg_tag); pTip->setPosition(ccp(pTip->getContentSize().width/2 - 25, m_pBg->getContentSize().height-pTip->getContentSize().height/2 - 30)); //左上角提示字符串 CCLabelTTF* pTipStr = CCLabelTTF::create(LFStrings::getValue("ShangdiangTipStr_lefttop_juqing").c_str(), fontStr_katong, 24, CCSizeMake(210, 80), kCCTextAlignmentLeft); m_pBg->addChild(pTipStr, 1, lefttop_tip_str_tag); pTipStr->setPosition(ccp(pTip->getPositionX() + 20, pTip->getPositionY() - 25)); pTipStr->setString(""); //中间提示字符 CCLabelTTF* pTipCenterStr = CCLabelTTF::create(LFStrings::getValue("ShangdiangTipStr_center_01").c_str(), fontStr_katong, 24); m_pBg->addChild(pTipCenterStr, 1, center_tip_str_tag); pTipCenterStr->setColor(ccc3(150, 60, 20)); pTipCenterStr->setPosition(ccp(m_pBg->getContentSize().width/2, m_pBg->getContentSize().height - 160)); pTipCenterStr->setString(""); //右边星星数 CCLabelAtlas* lable = CCLabelAtlas::create( "0123456789", ResManager::getManager()->getSharedFilePath(g_seasonlayerPath+"season_star_amount.png").c_str(), 30, 47,//24 '0'); m_pBg->addChild(lable, 1, star_count_str_tag); lable->setScale(0.6f); char charStarCount[10] = {}; int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore(); sprintf(charStarCount, "%d", iStarCount); lable->setString(charStarCount); lable->setPosition(ccp(m_pBg->getContentSize().width - 120, m_pBg->getContentSize().height - 175)); //右边字符 CCSprite* pShuzi = CCSprite::create(ResManager::getManager()->getFilePathByLanguageType(g_seasonlayerPath+"season_amount.png").c_str()); m_pBg->addChild(pShuzi, 1); pShuzi->setScale(0.6f); pShuzi->setPosition(ccp(lable->getPositionX() - 50, pTipCenterStr->getPositionY())); //右边星星图标 CCSprite* pXingxing = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_xiaogk+"YX_start.png").c_str()); m_pBg->addChild(pXingxing, 1); pXingxing->setPosition(ccp(pShuzi->getPositionX() - 50, pShuzi->getPositionY())); }
void GameScene::resetTree(void) { for (int i = kTree1Tag; i <= kTree3Tag; i++) { float delta = jumper_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2); CCSprite * tree = (CCSprite *)this->getChildByTag(i); tree->setPosition(ccp(tree->getPosition().x,tree->getPosition().y-delta)); if (tree->getPosition().y <= -0.5*CCDirector::sharedDirector()->getWinSize().height ) { float posY; if (i == kTree1Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree3Tag); if (isPowerPicked) { posY = temp->getPosition().y + temp->getContentSize().height*0.94; } else { posY = temp->getPosition().y + temp->getContentSize().height*0.97; } tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree2Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree1Tag); if (isPowerPicked) { posY = temp->getPosition().y + temp->getContentSize().height*0.94; } else { posY = temp->getPosition().y + temp->getContentSize().height*0.97; } tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree3Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree2Tag); if (isPowerPicked) { posY = temp->getPosition().y + temp->getContentSize().height*0.94; } else { posY = temp->getPosition().y + temp->getContentSize().height*0.97; } tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } } } for (int j = kTree11Tag; j <= kTree33Tag; j++) { float delta = jumper_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2); CCSprite * tree = (CCSprite *)this->getChildByTag(j); tree->setPosition(ccp(tree->getPosition().x,tree->getPosition().y-delta*0.5)); if (tree->getPosition().y <= -0.5*CCDirector::sharedDirector()->getWinSize().height ) { float posY; if (j == kTree11Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree33Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.98; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (j == kTree22Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree11Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.98; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (j == kTree33Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree22Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.98; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } } } }
CCSprite* IOSStoreLayer::createCellSpr(int index, CellInfo* daojuInfo) { CCSprite* pDaoju = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_bg.png").c_str()); //显示道具的名字 CCLabelTTF* pTitle = CCLabelTTF::create(daojuInfo->nameStr.c_str(), fontStr_katong, 24); pDaoju->addChild(pTitle); pTitle->setColor(fontColor_Store); pTitle->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height - 40)); //显示道具的描述 CCLabelTTF* pDescribe = CCLabelTTF::create(daojuInfo->describeStr.c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentLeft); pDaoju->addChild(pDescribe); pDescribe->setAnchorPoint(ccp(0, 0.5f)); pDescribe->setHorizontalAlignment(kCCTextAlignmentLeft); pDescribe->setPosition(ccp(10, 85)); if (daojuInfo->bBaoxiang) { pDescribe->setPosition(ccp(10, 65)); } //显示图标 CCSprite* pIcon = CCSprite::create(daojuInfo->iconNameStr.c_str()); // if (pIcon) { pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20)); pDaoju->addChild(pIcon, 1); CCSprite *mask = CCSprite::create(ResManager::getManager()->getSharedFilePath(g_storelayerPath+"main_shangdian_daoju_fugai.png").c_str()); pDaoju->addChild(mask, 2); mask->setPosition(ccp(pIcon->getPositionX(), pIcon->getPositionY()+20)); } //宝箱需要设置缩放为35% if (daojuInfo->bBaoxiang) { pIcon->setScale(0.35f); } //底部按钮 CCMenuItemImage* pMenuItem = CCMenuItemImage::create( daojuInfo->btnIconNorNameStr.c_str(), daojuInfo->btnIconSelNameStr.c_str(), this, menu_selector(IOSStoreLayer::menuBtnCallBack)); //星星数不够就显示文字,够的话就显示开宝箱按钮 if (pMenuItem) { bool bMore = false; int iStarCount = GameInforEditer::getGameInfor()->getTotalFreeScore(); if (daojuInfo->bBaoxiang) { if (daojuInfo->iBaoxiangCount == 10) { if (iStarCount >= 95) { bMore = true; } } else if (daojuInfo->iBaoxiangCount == 1) { if (iStarCount >= 10) { bMore = true; } } } else { bMore = true; } CCMenu* pMenu = CCMenu::create(); pMenu->setPosition(CCPointZero); pDaoju->addChild(pMenu, 1); pMenu->addChild(pMenuItem); pMenuItem->setPosition(ccp(pDaoju->getContentSize().width/2, pMenuItem->getContentSize().height/2)); pMenu->setTouchPriority(kCCMenuHandlerPriority-3); pMenuItem->setVisible(false); if (bMore) { pMenuItem->setVisible(true); } else if (daojuInfo->bBaoxiang) { //星星不足时,显示的字符串 CCLabelTTF* pTip = CCLabelTTF::create(LFStrings::getValue("Starless").c_str(), fontStr_katong, 24, CCSizeMake(200, 60), kCCTextAlignmentCenter); pDaoju->addChild(pTip,1); pTip->setPosition(ccp(pDaoju->getContentSize().width/2, pMenuItem->getContentSize().height/2+5)); } } //宝箱和购买星星区别加载 if (daojuInfo->bBaoxiang) { //十个宝箱 if (daojuInfo->iBaoxiangCount == 10) { pIcon = CCSprite::create(daojuInfo->iconBgNameStr.c_str()); if (pIcon) { pIcon->setPosition(ccp(pDaoju->getContentSize().width/2, pDaoju->getContentSize().height/2+20)); pDaoju->addChild(pIcon); pIcon->setScale(0.35f); } //十次 pMenuItem->setTag(tentimes_btn_tag); } else if (daojuInfo->iBaoxiangCount == 1) { //一次 pMenuItem->setTag(onetimes_btn_tag); } } else { //按照价格来设置购买按钮的tag pMenuItem->setTag(daojuInfo->iPrice); } return pDaoju; }
void GameScene::resetPlatform(void) { // We set this to -1 to initialize the first platform y coordinate if(currentPlatformY < 0) { currentPlatformY = (float) kStartingCurrentPlatformY; } else { // If not the first one then randomly determine a y coordinate for the platform currentPlatformY += rand() % (int)(currentMaxPlatformStep - kMinPlatformStep) + kMinPlatformStep; // If the current platofmr step is less than the max (top of screen) then increment it if(currentMaxPlatformStep < kMaxPlatformStep) { currentMaxPlatformStep += 0.5f; } } CCSprite *platform = (CCSprite*)getChildByTag(currentPlatformTag); CCSprite * tree = CCSprite::create("tree.png"); if ( rand() % 2 == 1) platform->setScaleX(-1.0f); float x; CCSize size = platform->getContentSize(); // If the current platform is the first one initialized then just center it if (currentPlatformY == (float)kStartingCurrentPlatformY) { x = (float) CCDirector::sharedDirector()->getWinSize().width/2; } else { if ( rand() % 2 == 1) { x = (float) CCDirector::sharedDirector()->getWinSize().width/2+ tree->getContentSize().width*0.7; } else { x = (float) CCDirector::sharedDirector()->getWinSize().width/2- tree->getContentSize().width*0.7; } } platform->setPosition(ccp(x,currentPlatformY)); // If the platform is to have to bonus then put it there. if (platformCount == coin50Platform) { CCSprite *coin1 = (CCSprite*)getChildByTag(coin50Count); coin1->setPosition(ccp(x, currentPlatformY+30)); coin1->setVisible(true); coin50Platform += k50CoinStartPlatform+randomValueBtween(5, 2); if (platformCount == coin100Platform) { coin100Platform += k100CoinStartPlatform+randomValueBtween(5, 2); } if (platformCount == coinJumpPlatform) { coinJumpPlatform += kJumpCoinStartPlatform+randomValueBtween(5, 2); } coin50Count++; if (coin50Count >= kBonusStartTag + kNumCoines) { coin50Count = kBonusStartTag; } } else if (platformCount == coin100Platform) { CCSprite *coin1 = (CCSprite*)getChildByTag(coin100Count); coin1->setPosition(ccp(x, currentPlatformY+30)); coin1->setVisible(true); coin100Count++; if (coin100Count >= kBonusStartTag + kNumCoines+30) { coin100Count = kBonusStartTag+30; } coin100Platform += k100CoinStartPlatform+randomValueBtween(5, 2); if (platformCount == coinJumpPlatform) { coinJumpPlatform += kJumpCoinStartPlatform+randomValueBtween(5, 2); } } else if (platformCount == coinJumpPlatform) { CCSprite *coin1 = (CCSprite*)getChildByTag(coinJumpCount); coin1->setPosition(ccp(x, currentPlatformY+30)); coin1->setVisible(true); coinJumpPlatform += kJumpCoinStartPlatform+randomValueBtween(5, 2); coinJumpCount++; if (coinJumpCount >= kBonusStartTag + kNumCoines+60) { coinJumpCount = kBonusStartTag+60; } } platformCount++; }
//============================================================= //============================================================= void CC3DCircleListLayer::initDataCircle(float fEllipseA,float fEllipseB,CCSize itemSize,CCArray* pArray,bool bFlipY) { if(!pArray) return; m_itemSize = itemSize; m_fEllipseA = fEllipseA; m_fEllipseB = fEllipseB; int nAllItemCount = pArray->count(); float fCircleStepDegree = (2*M_PI)/nAllItemCount; float fMoveX = getContentSize().width*0.5; float fMoveY = getContentSize().height*0.5; m_pButtonArray->removeAllObjects(); for(int i=0;i<nAllItemCount;i++) { float fCurDegree = fCircleStepDegree * (i+1); float fCircleX = m_fEllipseA * cosf(fCurDegree); float fCircleY = m_fEllipseB * sinf(fCurDegree); fCircleX += fMoveX; fCircleY += fMoveY; CCSprite* pSprite = (CCSprite*)pArray->objectAtIndex(i); CCScale9Sprite* pScaleSprite = CCScale9Sprite::createWithSpriteFrame(pSprite->displayFrame()); CCButton* pButton = CCButton::create( pScaleSprite); pButton->setTag(i); pButton->setZoomOnTouchDown(false); CCPoint point = ccp(fCircleX,fCircleY); pButton->setPosition(point); CCString* pString = new CCString(); pString->initWithFormat("%f",fCurDegree); pButton->setUserData(pString); pButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CC3DCircleListLayer::clickButton), CCControlEventTouchUpInside); addChild(pButton); m_pButtonArray->addObject(pButton); if(bFlipY) { CCSize buttonSize = pButton->getContentSize(); CCSprite* pFlipYSprite = CCSprite::createWithTexture(pSprite->getTexture()); CCRect oldRect = pSprite->getTextureRect(); pFlipYSprite->setFlipY(true); pFlipYSprite->setOpacity(255*0.5); pFlipYSprite->setAnchorPoint(ccp(0.5,1)); pFlipYSprite->setPosition(ccp(buttonSize.width*0.5,0)); pButton->addChild(pFlipYSprite); } // CCSize buttonSize = pButton->getContentSize(); // char testChr[32]; // sprintf(testChr, "%d",i); // CCLabelTTF* pTestLabel = CCLabelTTF::create(testChr, "Arial", 52); // pTestLabel->setColor(ccRED); // pTestLabel->setPosition(ccp(buttonSize.width*0.5,buttonSize.height*0.5)); // pButton->addChild(pTestLabel); } refreshItemWithMoveDegree(0); }
void GameScene::step(float dt) { particles_counter += dt; if (particles_counter > 0.15) { particles->setEmissionRate(0); } // Return if game suspended if(gameSuspended) return; // Get the jumper sprite CCSprite *jumper = (CCSprite*)getChildByTag(kjumper); // Update the player x position based on velocity and delta time jumper_pos.x += jumper_vel.x * dt; jumper->setRotation(jumper_vel.x); // Flip the player based on it's x velocity and current looking direction if(jumper_vel.x < -30.0f && jumperLookingRight) { jumperLookingRight = false; jumper->setScaleX(-1.0f); } else if (jumper_vel.x > 30.0f && !jumperLookingRight) { jumperLookingRight = true; jumper->setScaleX(1.0f); } // Calculate the max and min x values for the jumper // based on the screen and jumper widths CCSize jumper_size = jumper->getContentSize(); // float max_x = (float)CCDirector::sharedDirector()->getWinSize().width - jumper_size.width/2; // float min_x = jumper_size.width/2; // Limit the jumper position based on max and min values allowed // if(jumper_pos.x>max_x) jumper_pos.x = max_x; // if(jumper_pos.x<min_x) jumper_pos.x = min_x; float max_x = (float)CCDirector::sharedDirector()->getWinSize().width + jumper_size.width/2.0; float min_x = -jumper_size.width/2.0; // Limit the character position based on max and min values allowed if(jumper_pos.x>max_x) jumper_pos.x = jumper_size.width/2.0; if(jumper_pos.x<min_x) jumper_pos.x = (float)CCDirector::sharedDirector()->getWinSize().width - jumper_size.width/2.0; // Update the jumper velocity based on acceleration and time // if (isPowerPicked) // { // jumper_vel.y += (jumper_acc.y * dt)*3; // } // else { jumper_vel.y += jumper_acc.y * dt; } // Update the jumper y positin based on velocity and time jumper_pos.y += jumper_vel.y * dt; //////////////////////////////////////////////////////////////////////////// // Handle the bonus scoring float delta = jumper_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2); // If bonus is visible then see if the jumper is within range to get the bonus // If the jumper has stopped moving then make it jump from the platform it is on int t; if(jumper_vel.y < 0) { t = kPlatformsStartTag; // Search through all the platforms and compare the jumpers position with the platfor position for(t; t < kPlatformsStartTag + kNumPlatforms; t++) { CCSprite *platform = (CCSprite*)getChildByTag(t); CCSize platform_size = platform->getContentSize(); CCPoint platform_pos = platform->getPosition(); max_x = platform_pos.x - platform_size.width/2 - 2; min_x = platform_pos.x + platform_size.width/2 + 2; float min_y = platform_pos.y + (platform_size.height+jumper_size.height)/2 - kPlatformTopPadding; if(jumper_pos.x > (max_x) && jumper_pos.x < (min_x) && jumper_pos.y > platform_pos.y && jumper_pos.y < min_y) { if (platform->getTag() == kKillerPlatformTag) { coin50Platform = 12; coin100Platform = 15; coinJumpPlatform = 25; SharedData::getSharedInstance()->gameover_Text = "Gameover"; CCScene *pScene = GameOverScene::scene(); CCDirector::sharedDirector()->pushScene(pScene); this->unscheduleAllSelectors(); } else { jump(); break; // Can only jump from one platform at a time to break out of the loop } } } // If the jumper has fallen below the screen then game over if(jumper_pos.y < - jumper_size.height/2) { coin50Platform = 12; coin100Platform = 15; coinJumpPlatform = 25; SharedData::getSharedInstance()->gameover_Text = "Gameover"; CCScene *pScene = GameOverScene::scene(); CCDirector::sharedDirector()->pushScene(pScene); this->unscheduleAllSelectors(); // resetjumper(); } } else if ( jumper_pos.y > ((float)CCDirector::sharedDirector()->getWinSize().height / 2)) { // If jumper position is greater than the middle of the screen then move the platforms // the difference between the jumper y position and middle point of the screen resetTree(); // Set the jumper y position to the middle of the screen jumper_pos.y = (float)CCDirector::sharedDirector()->getWinSize().height / 2; // Move the current platform y by the delta amount currentPlatformY -= delta; // Move the clouds vertically and reset if necessary t = kCloudsStartTag; for (t; t < kCloudsStartTag + kNumClouds; t++) { CCSprite *cloud = (CCSprite*) getChildByTag(t); CCPoint pos = cloud->getPosition(); // Calculate new position for cloud pos.y -= delta * cloud->getScaleY() * 0.8f; // If the cloud is off the screen then need to reset this cloud else set its new position if (pos.y < -cloud->getContentSize().height/2) { currentCloudTag = t; resetCloud(); } else { // Update the new y position for the cloud. cloud->setPosition(pos); } } // Move the platforms vertically and reset if necessary t = kPlatformsStartTag; int t_coin = kBonusStartTag; for (t; t < kPlatformsStartTag + kNumPlatforms; t++) { CCSprite *platform = (CCSprite*)getChildByTag(t); CCPoint pos = platform->getPosition(); // Calculate new position for platform pos = ccp(pos.x, pos.y - delta); // If the platform is off the screen then reset the platform else set its new position if(pos.y < - platform->getContentSize().height/2) { currentPlatformTag = t; resetPlatform(); } else { platform->setPosition(pos); } } //move particle system if (particles) { CCPoint pos = particles->getPosition(); pos.y -= delta; particles->setPosition(pos); } // If the bonus is visible then adjust it's y position // Update score based on how much the jumper has moved score += (int)delta*0.3 ; // if (score >= target_Score) // { // SharedData::getSharedInstance()->gameover_Text = "Level Cleared"; // CCScene *pScene = GameOverScene::scene(); // CCDirector::sharedDirector()->pushScene(pScene); // this->unscheduleAllSelectors(); // } // Display the new score value char scoreStr[10] = {0}; sprintf(scoreStr, "%d", score); CCLabelTTF* scoreLabel = (CCLabelTTF*) getChildByTag(kScoreLabel); scoreLabel->setString(scoreStr); int t_coins = kBonusStartTag; for (t_coins; t_coins < (kNumCoines + kBonusStartTag); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; CCPoint pos = coin->getPosition(); { // Calculate new position of coin pos.y -= delta; // If the coin is off the screen then reset the coin else set its new position if(pos.y < -coin->getContentSize().height/2 ) { // resetCoin(); } else { coin->setPosition(pos); } } } } t_coins = kBonusStartTag+30; for (t_coins; t_coins < (kNumCoines + kBonusStartTag+30); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; CCPoint pos = coin->getPosition(); { // Calculate new position of coin pos.y -= delta; // If the coin is off the screen then reset the coin else set its new position if(pos.y < -coin->getContentSize().height/2 ) { // resetCoin(); } else { coin->setPosition(pos); } } } } t_coins = kBonusStartTag+60; for (t_coins; t_coins < (kNumCoines + kBonusStartTag+60); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; CCPoint pos = coin->getPosition(); { // Calculate new position of coin pos.y -= delta; // If the coin is off the screen then reset the coin else set its new position if(pos.y < -coin->getContentSize().height/2 ) { // resetCoin(); } else { coin->setPosition(pos); } } } } } int t_coins = kBonusStartTag; for (t_coins; t_coins < (kNumCoines + kBonusStartTag); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; // If the player is within range of the coin value then award the prize if(jumper_pos.x > coin_pos.x - range && jumper_pos.x < coin_pos.x + range && jumper_pos.y > coin_pos.y - range && jumper_pos.y < coin_pos.y + range ) { // Build the score string to display char scoreStr[10] = {0}; score += 50; sprintf(scoreStr, "%d", score); CCLabelTTF* scoreLabel = (CCLabelTTF*) getChildByTag(kScoreLabel); scoreLabel->setString(scoreStr); coin->setVisible(false); } } } t_coins = kBonusStartTag+30; for (t_coins; t_coins < (kNumCoines + kBonusStartTag+30); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; // If the player is within range of the coin value then award the prize if(jumper_pos.x > coin_pos.x - range && jumper_pos.x < coin_pos.x + range && jumper_pos.y > coin_pos.y - range && jumper_pos.y < coin_pos.y + range ) { // Build the score string to display char scoreStr[10] = {0}; score += 100; sprintf(scoreStr, "%d", score); CCLabelTTF* scoreLabel = (CCLabelTTF*) getChildByTag(kScoreLabel); scoreLabel->setString(scoreStr); coin->setVisible(false); } } } t_coins = kBonusStartTag+60; for (t_coins; t_coins < (kNumCoines + kBonusStartTag+60); t_coins++) { //////////////////////////////////////////////////////////////////////////// // Handle the coin scoring CCSprite *coin = (CCSprite*)getChildByTag(t_coins); // If coin is visible then see if the character is within range to get the coin if(coin->isVisible() ) { CCPoint coin_pos = coin->getPosition(); float range = 30.0f; // If the player is within range of the coin value then award the prize if(jumper_pos.x > coin_pos.x - range && jumper_pos.x < coin_pos.x + range && jumper_pos.y > coin_pos.y - range && jumper_pos.y < coin_pos.y + range ) { // Build the score string to display this->powerPicked(); coin->setVisible(false); } } } for (int i = kTree1Tag; i <= kTree3Tag; i++) { float delta = jumper_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2); CCSprite * tree = (CCSprite *)this->getChildByTag(i); if ( jumper_pos.y > ((float)CCDirector::sharedDirector()->getWinSize().height / 2)) { tree->setPosition(ccp(tree->getPosition().x,tree->getPosition().y-delta)); } if (tree->getPosition().y <= -0.5*CCDirector::sharedDirector()->getWinSize().height ) { float posY; if (i == kTree1Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree3Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree2Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree1Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree3Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree2Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } } } for (int i = kTree11Tag; i <= kTree33Tag; i++) { float delta = jumper_pos.y - ((float)CCDirector::sharedDirector()->getWinSize().height / 2); CCSprite * tree = (CCSprite *)this->getChildByTag(i); if ( jumper_pos.y > ((float)CCDirector::sharedDirector()->getWinSize().height / 2)) { tree->setPosition(ccp(tree->getPosition().x,tree->getPosition().y-delta*0.1)); } if (tree->getPosition().y <= -0.5*CCDirector::sharedDirector()->getWinSize().height ) { float posY; if (i == kTree11Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree33Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree22Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree11Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } else if (i == kTree33Tag) { CCSprite * temp = (CCSprite *)this->getChildByTag(kTree22Tag); posY = temp->getPosition().y + temp->getContentSize().height*0.99; tree->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width*0.5, posY)); } } } // Set the jumpers position jumper->setPosition(jumper_pos); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize size = CCDirector::sharedDirector()->getVisibleSize(); CCSprite* pBackground = CCSprite::create("background.png"); pBackground->setPosition(ccp(size.width / 2, size.height / 2)); addChild(pBackground); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); CCPoint posBR = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y); CCPoint posBC = ccp(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width/2, pEGLView->getVisibleOrigin().y); CCPoint posTL = ccp(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height); // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(posBR.x - 20, posBR.y + 20) ); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); CCPoint posStep = ccp(150, -150); CCPoint beginPos = ccpAdd(posTL, ccpMult(posStep, 0.5f)); int line = 0; int row = 0; for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) { CCMenuItemImage* pMenuItem = CCMenuItemImage::create(s_EventMenuItem[i].id.c_str(), s_EventMenuItem[i].id.c_str(), this, menu_selector(HelloWorld::eventMenuCallback)); pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag); CCPoint pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); CCSize itemSize = pMenuItem->getContentSize(); if ((pos.x + itemSize.width / 2) > posBR.x) { line += 1; row = 0; pos = ccpAdd(beginPos, ccp(posStep.x * row, posStep.y * line)); } row += 1; pMenuItem->setPosition(pos); } CCLabelTTF* label = CCLabelTTF::create("Reload all plugins", "Arial", 24); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(HelloWorld::reloadPluginMenuCallback)); pMenuItem->setAnchorPoint(ccp(0.5f, 0)); pMenu->addChild(pMenuItem, 0); pMenuItem->setPosition(posBC); return true; }
void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { m_nCurrnetPage = data->nRow + 1; CCListViewCell *cell = CCListViewCell::node(); cell->setOpacity(0); cell->setContentSize(m_pList->getContentSize()); cell->setSelectionColor(ccc4(0, 0, 0, 0)); data->cell = cell; CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); CCSize size = CCSize(listItemSize.width * 0.9f, listItemSize.height * 0.6f); sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); m_labelPage->setString(m_pszString); float offX = 0.0f, offY = 0.0f, offsetX = 0.0f, offsetY = 0.0f; CC_UNUSED_PARAM(offsetY); int nCount = 0; int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; int nEnd = nStart + NUM_PER_PAGE; CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pTextures, pElement) { if (nCount >= nStart && nCount < nEnd) { string key = pElement->getStrKey(); CCTexture2D* textrue = (CCTexture2D*)pElement->getObject(); //textrue = m_pTextures->objectForKey(*it); if (textrue) { // reference count sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); CCLabelTTF *labelCount = CCLabelTTF::create(m_pszString, "Lucida Grande", 16); if (textrue->retainCount() - 2 > 0) { labelCount->setColor(ccc3(0, 255, 0)); } else { labelCount->setColor(ccc3(255, 0, 0)); } offX = offsetX + listItemSize.width * 0.5f - labelCount->getContentSize().width * 0.5f; offY = (listItemSize.height - size.height) * 0.5f - labelCount->getContentSize().height; labelCount->setPosition(ccp(offX, offY)); labelCount->setAnchorPoint(ccp(0, 0)); cell->addChild(labelCount); // texture size sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); CCLabelTTF *labelSize = CCLabelTTF::create(m_pszString, "Lucida Grande", 16); offX = offsetX + listItemSize.width * 0.5f; offY = (listItemSize.height - size.height) * 0.5f + size.height; labelSize->setPosition(ccp(offX, offY)); labelSize->setAnchorPoint(ccp(0.5f, 0)); cell->addChild(labelSize); // texture name int len = key.length(); int pos = 0; pos = key.rfind('\\') + 1; int pos2 = key.rfind('/') + 1; pos = pos > pos2 ? pos : pos2; string name = key.substr(pos, len - pos); sprintf(m_pszString, "%s", name.c_str()); CCSize dimensions = CCSizeMake(listItemSize.width * 0.9f, labelSize->getContentSize().height); CCLabelTTF *labelName = CCLabelTTF::create(m_pszString, dimensions, kCCTextAlignmentCenter, "Lucida Grande", 16); offX = offsetX + listItemSize.width * 0.5f; offY = offY + labelName->getContentSize().height; labelName->setPosition(ccp(offX, offY)); labelName->setAnchorPoint(ccp(0.5f, 0)); cell->addChild(labelName); CCSprite *sprite = CCSprite::create(textrue); sprite->setAnchorPoint(ccp(0, 0)); CCSize spriteSize = sprite->getContentSize(); float scale; if (spriteSize.width < size.width && spriteSize.height < size.height) { scale = 1; } else if (spriteSize.width * size.height >= spriteSize.height * size.width) { scale = size.width / spriteSize.width; } else { scale = size.height / spriteSize.height; } sprite->setScale(scale); spriteSize.width *= scale; spriteSize.height *= scale; offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5f; offY = (listItemSize.height - spriteSize.height) * 0.5f; sprite->setPosition(ccp(offX, offY)); cell->addChild(sprite); offsetX += listItemSize.width; } } ++nCount; } }