// 初始化底部Bar void ActivityView::initBottomBar(CCSize winSize) { /////////////////////////////////////////// 底部条 //////////////////////////////////////// this->footerBarNode = CCNode::create() ; this->footerBarNode->setAnchorPoint(ccp(0, 0)) ; this->footerBarNode->setPosition(ccp(0, -5)) ; this->addChild(this->footerBarNode) ; /////////////////////////////////////// 定义背景 ///////////////////////////////////////// // 背景 CCSprite* bottomBarBg = CCSprite::create("bg_bottom_bar.png") ; bottomBarBg->setAnchorPoint(ccp(0.5, 0)) ; bottomBarBg->setPosition(ccp(winSize.width/2, 0)) ; this->footerBarNode->addChild(bottomBarBg, 1) ; // 定义底部条高度 const float footerBarNode_height = bottomBarBg->getContentSize().height ; // 设置底部条的高和宽 this->footerBarNode->setContentSize(CCSizeMake(winSize.width, footerBarNode_height)) ; // 背景遮罩层 CCSprite* bottomBg = CCSprite::create("bg_bottom.png") ; bottomBg->setAnchorPoint(ccp(0, 1)) ; bottomBg->setPosition(ccp(0, footerBarNode_height)) ; this->footerBarNode->addChild(bottomBg, 0) ; CCSpriteBatchNode* bottomIcon = CCSpriteBatchNode::create("bg_bottom_icon.png") ; // 左边的icon CCSprite* leftIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ; leftIcon->setAnchorPoint(ccp(0, 0)) ; leftIcon->setPosition(ccp(0, 0)) ; this->footerBarNode->addChild(leftIcon, 1) ; // 右边的icon CCSprite* rightIcon = CCSprite::createWithTexture(bottomIcon->getTexture()) ; rightIcon->setAnchorPoint(ccp(1, 0)) ; rightIcon->setPosition(ccp(winSize.width, 0)) ; rightIcon->setFlipX(true) ; // 水平翻转 this->footerBarNode->addChild(rightIcon, 1) ; const float menuItem_margin = 50.0f ; // 距离中间位置的距离 const float menuItem_padding = 100.0f ; // menuItem之间的间隔 // 底部菜单 CCMenu* footerMenu = CCMenu::create() ; footerMenu->setContentSize(CCSizeMake(winSize.width, footerBarNode_height) ) ; footerMenu->setAnchorPoint(ccp(0, 0)) ; footerMenu->setPosition(ccp(0, 0)) ; this->footerBarNode->addChild(footerMenu, 2) ; // 活动菜单 CCMenuItemImage* activityMenuItem = CCMenuItemImage::create("menu_activity_n.png", "menu_activity_s.png", this, menu_selector(ActivityView::menuActivityClickCallback)) ; activityMenuItem->setAnchorPoint(ccp(1, 1)) ; activityMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin, footerBarNode_height-3)) ; footerMenu->addChild(activityMenuItem) ; // 获取menuItem宽度 const float menuItem_width = activityMenuItem->getContentSize().width ; // 信息菜单 CCMenuItemImage* infoMenuItem = CCMenuItemImage::create("menu_message_n.png", "menu_message_s.png", this, menu_selector(ActivityView::menuInfoClickCallback)) ; infoMenuItem->setAnchorPoint(ccp(1, 1)) ; infoMenuItem->setPosition(ccp(winSize.width/2-menuItem_margin-menuItem_width-menuItem_padding, footerBarNode_height-3)) ; footerMenu->addChild(infoMenuItem) ; // 商城菜单 CCMenuItemImage* shopMenuItem = CCMenuItemImage::create("menu_shop_n.png", "menu_shop_s.png", this, menu_selector(ActivityView::menuShopClickCallback)) ; shopMenuItem->setAnchorPoint(ccp(0, 1)) ; shopMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin, footerBarNode_height-3)) ; footerMenu->addChild(shopMenuItem) ; // 菜单菜单 CCMenuItemImage* moreMenuItem = CCMenuItemImage::create("menu_more_n.png", "menu_more_s.png" , this, menu_selector(ActivityView::menuMoreClickCallback)) ; moreMenuItem->setAnchorPoint(ccp(0, 1)) ; moreMenuItem->setPosition(ccp(winSize.width/2+menuItem_margin+menuItem_width+menuItem_padding, footerBarNode_height-3)) ; footerMenu->addChild(moreMenuItem) ; // 更多菜单背景 CCSprite* moreMenuBg = CCSprite::create("bg_more_menu.png") ; moreMenuBg->setAnchorPoint(ccp(0,0)) ; moreMenuBg->setPosition(ccp(0, 0)) ; const float moreMenu_width = moreMenuBg->getContentSize().width ; const float moreMenu_height = moreMenuBg->getContentSize().height ; // 更多菜单节点 moreMenuNode = CCNode::create() ; moreMenuNode->setContentSize(moreMenuBg->getContentSize()) ; // 设置moreMenuNode的尺寸 moreMenuNode->setAnchorPoint(ccp(1, 0)) ; moreMenuNode->setPosition(ccp(winSize.width-80, 80)) ; moreMenuNode->retain() ; // this->addChild(moreMenuNode, 5, MORE_MENU_NODE_TAG) ; moreMenuNode->addChild(moreMenuBg, 0) ; // 将背景加入到更多菜单中 // 更多菜单 CCMenu* moreMenu = CCMenu::create() ; moreMenu->setAnchorPoint(ccp(0, 0)) ; moreMenu->setPosition(ccp(0, 0)) ; moreMenuNode->addChild(moreMenu, 1, MORE_MENU_TAG) ; // 排行榜菜单项 CCMenuItemImage* rankingMenuItem = CCMenuItemImage::create("menu_ranking_n.png", "menu_ranking_s.png" , this, menu_selector(GameMenuView::menuRankingClickCallback)) ; rankingMenuItem->setAnchorPoint(ccp(0, 1)) ; rankingMenuItem->setPosition(ccp(10, moreMenu_height-10)) ; moreMenu->addChild(rankingMenuItem) ; // 任务菜单 CCMenuItemImage* taskMenuItem = CCMenuItemImage::create("menu_task_n.png", "menu_task_s.png" , this, menu_selector(GameMenuView::menuTaskClickCallback)) ; taskMenuItem->setAnchorPoint(ccp(1, 1)) ; taskMenuItem->setPosition(ccp(moreMenu_width-10, moreMenu_height-10)) ; moreMenu->addChild(taskMenuItem) ; // 好友菜单 CCMenuItemImage* friendMenuItem = CCMenuItemImage::create("menu_friend_n.png", "menu_friend_s.png", this, menu_selector(GameMenuView::menuFriendClickCallback)) ; friendMenuItem->setAnchorPoint(ccp(0, 0)) ; friendMenuItem->setPosition(ccp(10, 5)) ; moreMenu->addChild(friendMenuItem) ; // 客服菜单 CCMenuItemImage* customserviceMenuItem = CCMenuItemImage::create("menu_cs_n.png", "menu_cs_s.png", this, menu_selector(GameMenuView::menuSettingClickCallback)) ; customserviceMenuItem->setAnchorPoint(ccp(1, 0)) ; customserviceMenuItem->setPosition(ccp(moreMenu_width-10, 5)) ; moreMenu->addChild(customserviceMenuItem) ; }
bool CMainSelect::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } this->setTouchEnabled(true); // 创建背景 CCSize size = CCDirector::sharedDirector()->getWinSize(); CCSprite* backgroud = CCSprite::create("mainsel/bg.png"); backgroud->setPosition( ccp(size.width/2, size.height/2) ); this->addChild(backgroud); // 按钮 CCMenuItemImage *pLack = CCMenuItemImage::create("mainsel/lackNor.png", "mainsel/lackSel.png", this, menu_selector(CMainSelect::lakeCallback) ); CCMenuItemImage *pForest = CCMenuItemImage::create("mainsel/forestNor.png", "mainsel/forestSel.png", this, menu_selector(CMainSelect::forestCallback) ); CCMenuItemImage *pDesert = CCMenuItemImage::create("mainsel/desertNor.png", "mainsel/desertSel.png", this, menu_selector(CMainSelect::desertCallback) ); CCMenuItemImage *pPrairie = CCMenuItemImage::create("mainsel/prairieNor.png", "mainsel/prairieSel.png", this, menu_selector(CMainSelect::prairieCallback) ); pLack->setPosition( ccp(171, 437) ); pForest->setPosition( ccp(539, 401) ); pDesert->setPosition( ccp(864, 411) ); pPrairie->setPosition( ccp(392, 208) ); CCMenu* pMenu = CCMenu::create(pLack, pForest, pDesert, pPrairie, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu, 1); // 创建sprite sheet CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("mainsel/jingyu.plist"); CCSpriteBatchNode *spriteSheet = CCSpriteBatchNode::create("mainsel/jingyu.png"); this->addChild(spriteSheet); // 创建对象 CCSprite *sprite = CCSprite::createWithSpriteFrameName("jingyu01.png"); sprite->setPosition(ccp(920,220)); spriteSheet->addChild(sprite, 0); CCArray *arrShang = CCArray::create(); // 动画帧数组 for(int i=1; i<=8; ++i) { CCString *name = CCString::createWithFormat("jingyu%02d.png", i); arrShang->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString())); } CCArray *arrPeng = CCArray::create(); // 动画帧数组 for(int i=9; i<=11; ++i) { CCString *name = CCString::createWithFormat("jingyu%02d.png", i); arrPeng->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString())); } CCArray *arrPengRev = CCArray::createWithArray(arrPeng); arrPengRev->reverseObjects(); arrPeng->addObjectsFromArray(arrPengRev); CCFiniteTimeAction *delay = CCDelayTime::create(1); CCAnimate* anShang = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrShang, 0.25)); CCAnimate* anPeng = CCAnimate::create(CCAnimation::createWithSpriteFrames(arrPeng, 0.15)); sprite->runAction(CCRepeatForever::create((CCActionInterval*)CCSequence::create(anShang, delay, anPeng,anPeng, anPeng, anPeng, anPeng, anShang->reverse(),delay,delay,delay,NULL))); return true; }
bool CResultScoreLayer::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); ///////////////////////////// // 2. add a background image //score part int playerNum = CGameManager::GetInstance()->GetCurrentPlayerNumber(); CCPoint position; //«√∑π¿ÃæÓ ºˆø° µ˚∂Û Ω√¿€ ¡°¿ª ∞˪Í. position.x = (visibleSize.width / 2) - (RESULT_BACKGROUND_WIDTH * playerNum / 2); position.y = RESULT_BACKGROUND_POSITION_Y; int tileMax, goldMax, trashMax, tileMin, goldMin, trashMin; tileMax = goldMax = trashMax = 0; tileMin = goldMin = trashMin = INTMAX_MAX; // 점수 최대 최소 구하기 for (unsigned int i = 0; i < playerNum; ++i) { // 타일 갯수 갱신 int eachTileNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_NOTHING); tileMax = (eachTileNum > tileMax) ? eachTileNum : tileMax; tileMin = (eachTileNum < tileMin) ? eachTileNum : tileMin; // 케이크 갯수 갱신 int eachCakeNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_GOLD); goldMax = (eachCakeNum > goldMax) ? eachCakeNum : goldMax; goldMin = (eachCakeNum < goldMin) ? eachCakeNum : goldMin; // 쓰레기 갯수 갱신 int eachTrashNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_TRASH); trashMax = (eachTrashNum > trashMax) ? eachTrashNum : trashMax; trashMin = (eachTrashNum < trashMin) ? eachTrashNum : trashMin; } // 4는 최대 아이콘 표시 개수 - 지금은 하드코딩임 // float tileUnit = float(tileMax - tileMin) / 4; float goldUnit = float(goldMax - goldMin) / 4; float trashUnit = float(trashMax - trashMin) / 4; for (unsigned int i = 0; i < playerNum; ++i) { int tileNum, cakeNum, trashNum; tileNum = cakeNum = trashNum = 0; tileNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_NOTHING); cakeNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_GOLD); trashNum = CGameManager::GetInstance()->GetElementCount(i, ITEM_TRASH); // background CCSprite* pBackgorund = CCSprite::create(RESULT_BACKGROUND_IMAGE[i].c_str()); pBackgorund->setAnchorPoint(ccp(0, 0) ); pBackgorund->setPosition(ccp(position.x, position.y) ); addChild(pBackgorund, 0); // character int characterId = CGameManager::GetInstance()->GetCharacterIdByPlayerId(i); CCSprite* pFace; //Ω¬∆– ø©∫Œø° µ˚∂Û ƒ≥∏Ø≈Õ ¿Ãπሠª˝º∫ if ( CGameManager::GetInstance()->IsWinner(i) ) pFace = CCSprite::create(RESULT_CHARACTER_WIN_IMAGE[characterId].c_str()); else pFace = CCSprite::create(RESULT_CHARACTER_LOSE_IMAGE[characterId].c_str()); pFace->setAnchorPoint(ccp(0.5,0) ); pFace->setPosition(ccp(position.x + RESULT_CHARACTER_IMAGE_POSITION_X_MARGIN, position.y + RESULT_CHARACTER_IMAGE_POSITION_Y_MARGIN)); addChild(pFace,1); //winner flag if ( CGameManager::GetInstance()->IsWinner(i) ) { CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(RESULT_WINNER.c_str()); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(RESULT_WINNER_PLIST.c_str()); CCArray* animFrames = CCArray::createWithCapacity(7); char str[100] = {0}; for(int i = 1; i < 8; i++) { sprintf(str, "result_winner_ani_000%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames->addObject(frame); } CCSprite*pWinner = CCSprite::createWithSpriteFrameName("result_winner_ani_00001.png"); pWinner->setAnchorPoint(ccp(0.5,0)); spritebatch->addChild(pWinner); addChild(spritebatch,2); CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames,0.3f); CCRepeatForever* repeatAction = CCRepeatForever::create(CCAnimate::create(animation)); pWinner->runAction(repeatAction); pWinner->setPosition(ccp(position.x + RESULT_CHARACTER_IMAGE_POSITION_X_MARGIN, position.y + RESULT_CHARACTER_IMAGE_POSITION_Y_MARGIN)); } //player name CCLabelTTF* pName = CCLabelTTF::create(CGameManager::GetInstance()->GetPlayerName(i).c_str(), GAME_FONT, 48 ); pName->setAnchorPoint(ccp(0.5, 0.5)); pName->setPosition(ccp(position.x + RESULT_PLAYER_NAME_POSITION_X, position.y + RESULT_PLAYER_NAME_POSITION_Y) ); addChild(pName,1); //total score std::string playerScore = std::to_string(CGameManager::GetInstance()->GetTotalScore(i) ); CCLabelTTF* pScore = CCLabelTTF::create(playerScore.c_str(), GAME_FONT, 72 ); pScore->setAnchorPoint(ccp(0.5,0.5)); pScore->setColor(ccc3(80, 80, 80)); pScore->setPosition(ccp(position.x + RESULT_PLAYER_SCORE_POSITION_X_MARGIN, position.y + RESULT_PLAYER_SCORE_POSITION_Y_MARGIN)); addChild(pScore,0); // tile + * + count // origin CCSprite* pTile = CCSprite::create(RESULT_FLOWER_IMAGE[characterId].c_str()); pTile->setPosition(ccp(position.x + RESULT_FLOWER_IMAGE_X_MARGIN , position.y + RESULT_ITEM_IMAGE_Y_MARGIN ) ); pTile->setAnchorPoint(ccp(0.5, 0.0) ); addChild(pTile, 0); /* // 표시할 그림 수 결정 int weightedTileNum = (tileNum - tileMin) / tileUnit + 1; // 최대 최소 수 보정 if (tileNum == 0) weightedTileNum = 0; else if (tileNum == tileMax) weightedTileNum = 4; for (int eachItem = weightedTileNum; eachItem > 0; --eachItem ) { // 타일 그림 그리는 곳 CCSprite* pTile = CCSprite::create(RESULT_FLOWER_IMAGE[characterId].c_str()); pTile->setPosition(ccp(position.x + RESULT_FLOWER_IMAGE_X_MARGIN + ( (eachItem % 2 == 0) ? 20 : -20), position.y + RESULT_ITEM_IMAGE_Y_MARGIN + (4 - eachItem) * 20 ) ); pTile->setAnchorPoint(ccp(0.5, 0.0) ); pTile->setScale(1.0f - (0.1*eachItem) ); pTile->setOpacity(255 - (20*eachItem) ); // pTile->setScale(0.8f); addChild(pTile, 0); } */ std::string tileCount = std::to_string( tileNum ); CCLabelTTF* pTileCount = CCLabelTTF::create(tileCount.c_str(), GAME_FONT, 48 ); pTileCount->setPosition(ccp(position.x + RESULT_FLOWER_COUNT_X_MARGIN, position.y + RESULT_ITEM_COUNT_Y_MARGIN) ); pTileCount->setAnchorPoint(ccp(0.5, 0.0) ); this->addChild(pTileCount, 0); //gold + * + count /* // origin CCSprite* pGold = CCSprite::create(RESULT_GOLD_IMAGE[0].c_str()); pGold->setPosition(ccp(position.x + RESULT_GOLD_IMAGE_X_MARGIN, position.y + RESULT_ITEM_IMAGE_Y_MARGIN) ); pGold->setAnchorPoint(ccp(0.5, 0.0) ); addChild(pGold, 0); */ // 표시할 그림 수 결정 int weightedGoldNum = (cakeNum - goldMin) / goldUnit + 1; // 최대 최소 수 보정 if (cakeNum == 0) weightedGoldNum = 0; else if (cakeNum == goldMax) weightedGoldNum = 4; for (int eachItem = weightedGoldNum; eachItem > 0; --eachItem ) { // 케익 그림 그리는 곳 CCSprite* pTile = CCSprite::create(RESULT_GOLD_IMAGE[0].c_str()); pTile->setPosition(ccp(position.x + RESULT_GOLD_IMAGE_X_MARGIN + ( (eachItem % 2 == 0) ? 20 : -20), position.y + RESULT_ITEM_IMAGE_Y_MARGIN + (weightedGoldNum - eachItem) * 40 ) ); pTile->setAnchorPoint(ccp(0.5, 0.0) ); pTile->setRotation( (eachItem % 2 == 0 ? -1 : 1) * 20 ); pTile->setScale(0.6f); // pTile->setOpacity(255 - (20*eachItem) ); addChild(pTile, 0); } std::string goldCount = std::to_string( cakeNum ); CCLabelTTF* pGoldCount = CCLabelTTF::create(goldCount.c_str(), GAME_FONT, 48 ); pGoldCount->setPosition(ccp(position.x + RESULT_GOLD_COUNT_X_MARGIN, position.y + RESULT_ITEM_COUNT_Y_MARGIN) ); pGoldCount->setAnchorPoint(ccp(0.5, 0.0) ); this->addChild(pGoldCount, 0); //Trash + * + count /* // origin CCSprite* pTrash = CCSprite::create(ResultTrashImage[0].c_str()); pTrash->setPosition(ccp(position.x + RESULT_TRASH_IMAGE_X_MARGIN, position.y + RESULT_ITEM_IMAGE_Y_MARGIN) ); pTrash->setAnchorPoint(ccp(0.5, 0.0) ); addChild(pTrash, 0); */ // 표시할 그림 수 결정 int weightedTrashNum = (trashNum - trashMin) / trashUnit; // 최대 최소 수 보정 if (trashNum > 0 && trashNum < 1) weightedTrashNum = 1; else if (trashNum == trashMax) weightedTrashNum = 4; for (int eachItem = weightedTrashNum; eachItem > 0; --eachItem ) { // 쓰레기 그림 그리는 곳 CCSprite* pTile = CCSprite::create(ResultTrashImage[0].c_str()); pTile->setPosition(ccp(position.x + RESULT_TRASH_IMAGE_X_MARGIN + ( (eachItem % 2 == 0) ? 15 : -20), position.y + RESULT_ITEM_IMAGE_Y_MARGIN + (weightedTrashNum - eachItem) * 40 ) ); pTile->setAnchorPoint(ccp(0.5, 0.0) ); pTile->setRotation( (eachItem % 2 == 0 ? -1 : 1) * 15 ); pTile->setScale(0.7f); // pTile->setOpacity(255 - (20*eachItem) ); addChild(pTile, 0); } std::string trashCount = std::to_string( trashNum ); CCLabelTTF* pTrashCount = CCLabelTTF::create(trashCount.c_str(), GAME_FONT, 48 ); pTrashCount->setPosition(ccp(position.x + RESULT_TRASH_COUNT_X_MARGIN, position.y + RESULT_ITEM_COUNT_Y_MARGIN) ); pTrashCount->setAnchorPoint(ccp(0.5, 0.0) ); this->addChild(pTrashCount, 0); //¥Ÿ¿Ω ¿Œµ¶Ω∫∏¶ ¿ß«ÿ ∆˜¡ˆº« x¡¬«• √fl∞°. position.x += RESULT_BACKGROUND_WIDTH; } return true; }
void CMO_tile::update( float delta ) { MO_OWNER tempOwner = CGameManager::GetInstance()->GetMapOwner(m_Index); if (tempOwner != m_Owner) { // 애니메이션이 시작하는 시간은 라인이 재생되는 시간 + 인덱스가 낮은 타일들이 모두 그려지는 시간(애니메이션이 있는 타일은 인덱스 1부터 시작하므로 자신의 인덱스에서 1을 빼서 재생시간 곱함) float delayTime = PLAYSCENE_ANIMATION_TIME + PLAYSCENE_ANIMATION_TIME * (CGameManager::GetInstance()->GetTileAnimationTurn(m_Index) - 1); // 애니메이션이 끝나는 시간을 지정함 CGameManager::GetInstance()->SetAnimationDelay(delayTime); CCDelayTime *dt = CCDelayTime::create(delayTime); m_Owner = tempOwner; int characterId = CGameManager::GetInstance()->GetCharacterIdByPlayerId(m_Owner); //background grass pTile = CCSprite::create(PLAYSCENE_LAND_OCCUPIED.c_str()); CCFadeIn* FadeIn = CCFadeIn::create(0.8f); CCAction *Fadeactions = CCSequence::create(dt, FadeIn, NULL); pTile->setOpacity(0); pTile->setAnchorPoint( ccp(0, 0.5f) ); pTile->runAction(Fadeactions); addChild(pTile,1); // CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(PLAYSCENE_LAND_ANI[characterId].c_str()); // CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(PLAYSCENE_LAND_ANI_PLIST[characterId].c_str()); CCArray* animFrames = CCArray::createWithCapacity(PLAYSCENE_LAND_FRAME); char str[100] = {0}; characterId++; for(int i = 1; i <= PLAYSCENE_LAND_FRAME; i++) { sprintf(str, "PLAYSCENE_ani_land_%d_000%02d.png",characterId,i); CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames->addObject(frame); } //first frame sprintf(str, "PLAYSCENE_ani_land_%d_00001.png",characterId); CCSprite *pElement = CCSprite::createWithSpriteFrameName(str); pElement->setAnchorPoint(ccp(0,0.5f)); spritebatch->addChild(pElement); addChild(spritebatch,2); CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames,PLAYSCENE_ANIMATION_TIME/PLAYSCENE_LAND_FRAME); CCAction* myTile = CCAnimate::create(animation); CCAction *actions = CCSequence::create(dt, myTile, NULL); pElement->runAction(actions); } }
void CMainMenuLayer::drawAnimation() { CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(MAIN_MENU1_ANI.c_str()); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(MAIN_MENU1_ANI_PLIST.c_str()); CCArray* animFrames1 = CCArray::createWithCapacity(40); char str[100] = {0}; for(int i = 1; i < 41; i++) { sprintf(str, "manin_menu1_000%02d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames1->addObject(frame); } CCSprite*pElement1 = CCSprite::createWithSpriteFrameName("manin_menu1_00001.png"); pElement1->setAnchorPoint(ccp(0,0)); spritebatch->addChild(pElement1); addChild(spritebatch,2); spritebatch->setTag(0); CCAnimation* animation1 = CCAnimation::createWithSpriteFrames(animFrames1,0.05f); CCRepeatForever* repeatAction1 = CCRepeatForever::create(CCAnimate::create(animation1)); pElement1->runAction(repeatAction1); pElement1->setPosition(CCPoint(MAIN_MENU1_IMG_POS)); //menu2 spritebatch = CCSpriteBatchNode::create(MAIN_MENU2_ANI.c_str()); //cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(MAIN_MENU2_ANI_PLIST.c_str()); CCArray* animFrames2 = CCArray::createWithCapacity(4); for(int i = 0; i < 4; i++) { sprintf(str, "main_img2_ani%d.PNG", i); CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames2->addObject(frame); } CCSprite*pElement2 = CCSprite::createWithSpriteFrameName("main_img2_ani0.PNG"); pElement2->setAnchorPoint(ccp(0,0)); spritebatch->addChild(pElement2); addChild(spritebatch,4); spritebatch->setTag(0); CCAnimation* animation2 = CCAnimation::createWithSpriteFrames(animFrames2,0.1f); CCRepeatForever* repeatAction2 = CCRepeatForever::create(CCAnimate::create(animation2)); pElement2->runAction(repeatAction2); pElement2->setPosition(CCPoint(MAIN_MENU2_IMG_POS)); //menu3 spritebatch = CCSpriteBatchNode::create(MAIN_MENU3_ANI.c_str()); //cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(MAIN_MENU3_ANI_PLIST.c_str()); CCArray* animFrames3 = CCArray::createWithCapacity(4); for(int i = 0; i < 4; i++) { sprintf(str, "main_img3_ani%d.PNG", i); CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames3->addObject(frame); } CCSprite*pElement3 = CCSprite::createWithSpriteFrameName("main_img3_ani0.PNG"); pElement3->setAnchorPoint(ccp(0,0)); spritebatch->addChild(pElement3); addChild(spritebatch,4); spritebatch->setTag(0); CCAnimation* animation3 = CCAnimation::createWithSpriteFrames(animFrames3,0.1f); CCRepeatForever* repeatAction3 = CCRepeatForever::create(CCAnimate::create(animation3)); pElement3->runAction(repeatAction3); pElement3->setPosition(CCPoint(MAIN_MENU3_IMG_POS)); }
bool ToTextLayer::DerLoadImg(Script* ts){ //meta const char* filename = ts->getstring("content"); // TO Change: // x <标志是否为切换. // tag <4001左边 4002右边 int x,y; int tag = ts->getint("tag"); int flag = ts->getint("flag"); static int last = 0; switch (flag) { case -1: //Grey it { TxTajie* tcs = (TxTajie*)getChildByTag(tag); if(tcs) { tcs->f_SetGrey(true); CCLog(">[GS]:gray the tj:%d",tag); } break; } case 1: // 0:change the color; { //[0803] CCLog(">[GS]change color:fade-%d,light-%d",last,tag); TxTajie* tcs = (TxTajie*)getChildByTag(last); if(last != 0&&tcs) { tcs->f_SetGrey(true); //[0803]CCLog(">[GS]:fade succes"); } tcs = (TxTajie*)getChildByTag(tag); if(tcs) { tcs->f_SetGrey(false); CCLog(">[GS]:Light tcs:%d", tag); } last = tag; return true; } case 2: // 2:载入动画 { x = ts->getfloat("x"); y = ts->getfloat("y"); removeChildByTag(tag); string name = ts->getstring("name"); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); GameManager::sharedLogicCenter()->f_cachetest(CCString::createWithFormat("%s.png",filename)->getCString()); CCSpriteBatchNode *sheet = CCSpriteBatchNode::create(CCString::createWithFormat("%s.png",filename)->getCString()); cache->addSpriteFramesWithFile(CCString::createWithFormat("%s.plist",filename)->getCString()); CCSpriterX* m_animator = CCSpriterX::create(CCString::createWithFormat("%s.SCML",filename)->getCString()); m_animator->setPosition(ccp(x,y)); m_animator->setAnchorPoint(CCPoint(0.5,0.5)); m_animator->setTag(tag); m_animator->setRotation(ts->getfloat("angel")); float scalex = ts->getfloat("scalex"); float scaley = ts->getfloat("scaley"); //if(scalex != 0) // m_animator->setScaleX(scalex); //if(scaley != 0) // m_animator->setScaleY(scaley); if(scalex != 0) { m_animator->setScale(scalex); //[0803]CCLog(">Scale."); } int zorder = ts->getint("zorder"); TagMap[name] = tag; PathMap[name] = filename; m_animator->PlayAnim(ts->getstring("animate"),ts->getint("repeat")); sheet->addChild(m_animator); addChild(sheet,ts->getint("zorder"),tag); break; } default: { x = ts->getfloat("x"); y = ts->getfloat("y"); if(y == 0) y = 180; string name = ts->getstring("name"); removeChildByTag(tag); GameManager::sharedLogicCenter()->f_cachetest(filename); //读入缓存文件,如果文件未缓存而filename不是本地文件,将会出现错误。 TxTajie* t_cs = TxTajie::create(filename); t_cs->setPosition(ccp(x,y)); t_cs->setAnchorPoint(CCPoint(0.5,0.5)); t_cs->setTag(tag); float aa = ts->getfloat("angel"); if(aa != 0) t_cs->setRotation(aa); int alpha = ts->getint("alpha"); if(alpha == 0) alpha = 255; t_cs->setOpacity(alpha); // Change default to No. If more is need, change the x flag. t_cs->setScale(0.8); //[0803]CCLog(">[GS]:Loading..."); int zorder = ts->getint("zorder"); addChild(t_cs,ts->getint("zorder")); if(zorder == 0 && ts->getint("link") == 0){ t_cs->f_SetGrey(true); CCLog(">[GS]:Load and grey:%d",tag); } if(ts->getint("link") == 1) { last = tag; //[0803]CCLog(">[GS]:Load and remain:%d",tag); } int tFlip = ts->getint("flip"); if (tFlip) t_cs->setFlipX(true); TagMap[name] = tag; PathMap[name] = filename; return true; break; } } //int x = ts->getfloat("x"); //int y = ts->getfloat("y"); //int tag = ts->getint("tag"); //string name = ts->getstring("name"); //removeChildByTag(tag); //GameManager::sharedLogicCenter()->f_cachetest(filename); //读入缓存文件,如果文件未缓存而filename不是本地文件,将会出现错误。 //CCSprite* tmp = CCSprite::create(filename); //tmp->setPosition(ccp(x,y)); //tmp->setAnchorPoint(CCPoint(0.5,0.5)); //tmp->setTag(tag); //tmp->setRotation(ts->getfloat("angel")); //addChild(tmp); //TagMap[name] = tag; //PathMap[name] = filename; return true; }
bool HelloWorld::init() { bool bRet = false; do { CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); CC_BREAK_IF(! pCloseItem); pCloseItem->setPosition(ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20)); CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); this->addChild(pMenu, 1); //解析tmx地图 map = CCTMXTiledMap::tiledMapWithTMXFile("0.tmx"); addChild(map); CCArray * pChildrenArray = map->getChildren(); CCSpriteBatchNode* child = NULL; CCObject* pObject = NULL; //遍历Tilemap的所有图层 CCARRAY_FOREACH(pChildrenArray, pObject) { child = (CCSpriteBatchNode*)pObject; if(!child) break; //给图层的纹理开启抗锯齿 child->getTexture()->setAntiAliasTexParameters(); } walkAnimation = new CCAnimation*[4]; walkAnimation[kDown] = createAnimationByDirection(kDown); walkAnimation[kRight] = createAnimationByDirection(kRight); walkAnimation[kLeft] = createAnimationByDirection(kLeft); walkAnimation[kUp] = createAnimationByDirection(kUp); //用frame0作为勇士的静态图 heroSprite = CCSprite::spriteWithSpriteFrame(walkAnimation[kDown]->getFrames()->getObjectAtIndex(0)); //heroSprite->setPosition(ccp(48, 48)); heroSprite->setAnchorPoint(CCPointZero); heroSprite->setPosition(positionForTileCoord(ccp(1, 11))); addChild(heroSprite); isHeroWalking = false; CCMenuItem *down = CCMenuItemFont::itemFromString("down", this, menu_selector(HelloWorld::menuCallBackMove)); CCMenuItem *left = CCMenuItemFont::itemFromString("left", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenuItem *right = CCMenuItemFont::itemFromString("right", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenuItem *up = CCMenuItemFont::itemFromString("up", this, menu_selector(HelloWorld::menuCallBackMove) ); CCMenu* menu = CCMenu::menuWithItems(down, left, right, up, NULL); //为了方便查找,给每个menuItem设置tag down->setTag(kDown); left->setTag(kLeft); right->setTag(kRight); up->setTag(kUp); //菜单项按间距50水平排列 menu->alignItemsHorizontallyWithPadding(50); addChild(menu); schedule(schedule_selector(HelloWorld::update)); bRet = true; } while (0);
//// merge small piece asprite to a big one CCNode* UIPicture::MergeSmallASprite(CCSprite* sprite) { if (!sprite) return NULL; CCTexture2D* ptexture = RecursiveFindTexture(sprite); if (ptexture == NULL) return sprite; if(sprite->getChildrenCount() == 0) { return sprite; } CCArray* secondTextureSprite = CCArray::create(); while (sprite->getChildrenCount() > 0) { CCTexture2D* ptexture = RecursiveFindTexture(sprite); /// create new batch node which used to store a series of sprites CCSpriteBatchNode * pNode = CCSpriteBatchNode::createWithTexture(ptexture); CCSize size = sprite->getContentSize(); CCPoint pt = sprite->getPosition(); pNode->setContentSize(size); pNode->setAnchorPoint(ccp(0.0, 0.0)); secondTextureSprite->removeAllObjects(); int i = 0; while(sprite->getChildrenCount() > 0) { CCArray* children = sprite->getChildren(); CCSprite* s1 = (CCSprite*)(children->lastObject()); sprite->removeChild(s1, false); if (s1->getTexture() == ptexture) { pNode->addChild(s1, i--); }else { secondTextureSprite->addObject(s1); } } /// copy second texture sprite to sprite CCObject* pTemp; CCARRAY_FOREACH(secondTextureSprite, pTemp) { CCSprite* pPst = (CCSprite*) pTemp; sprite->addChild(pPst); } if (!m_pSpriteNode) { /// 第一次创建时,取第一个sprite位置为当前m_pSpriteNode的位置 m_pSpriteNode = CCNode::create(); m_pSpriteNode->setPosition(pt); m_pSpriteNode->setContentSize(size); m_pSpriteNode->setAnchorPoint(sprite->getAnchorPoint()); pNode->setPosition(CCPointZero); }else { /// convert other sprite to local position CCPoint ptOrgio = m_pSpriteNode->getPosition(); pt = ccpSub(pt , ptOrgio); pNode->setPosition(pt); } m_pSpriteNode->addChild(pNode); }
// on "init" you need to initialize your instance bool Jugar::init() { bool bRet = false; do { if ( !CCLayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("background.plist"); CCSpriteBatchNode *batchNodeBackground = CCSpriteBatchNode::create("background.pvr.ccz"); this->addChild(batchNodeBackground, 0); CCSprite *background = CCSprite::createWithSpriteFrameName("backgroundPlay.png"); background->setPosition(ccp(winSize.width/2, winSize.height/2)); batchNodeBackground->addChild(background, 0); CCLabelTTF *labelPlayer1 = CCLabelTTF::create("Jugador 1", "aftershockdebris.ttf", 20); CCLabelTTF *labelPlayer2 = CCLabelTTF::create("Jugador 2", "aftershockdebris.ttf", 20); scoreLabelPlayer1 = CCLabelTTF::create("0", "aftershockdebris.ttf", 20); scoreLabelPlayer2 = CCLabelTTF::create("0", "aftershockdebris.ttf", 20); labelPlayer1->setColor(ccc3(0, 0, 0)); labelPlayer2->setColor(ccc3(0, 0, 0)); scoreLabelPlayer1->setColor(ccc3(0, 0, 0)); scoreLabelPlayer2->setColor(ccc3(0, 0, 0)); labelPlayer1->setPosition(ccp(winSize.width*0.4, winSize.height*0.9)); labelPlayer2->setPosition(ccp(winSize.width*0.4, winSize.height*0.8)); scoreLabelPlayer1->setPosition(ccp(winSize.width*0.6, winSize.height*0.9)); scoreLabelPlayer2->setPosition(ccp(winSize.width*0.6, winSize.height*0.8)); this->addChild(labelPlayer1, 1); this->addChild(labelPlayer2, 1); this->addChild(scoreLabelPlayer1, 1); this->addChild(scoreLabelPlayer2, 1); piso = 40; /* Creación y ubicación de jugadores */ int anchoClick; CCRect clickArea; int ancho = winSize.width/5; // 20% del ancho int inicio = winSize.width/10;// 10% del ancho anchoClick = winSize.width/3; CCRect area = CCRectMake(inicio, 0, ancho, winSize.height); clickArea = CCRectMake(0, 0, anchoClick, winSize.height); j1 = new Jugador(area, clickArea, this, callfuncO_selector(Jugar::golpearJ1), "stay1.png", "jump1.png", "hit11.png", "hit13.png", "hit14.png"); area.origin.x = winSize.width - ancho - inicio; clickArea.origin.x = winSize.width - anchoClick; if (players == 1) { area.origin.x -= inicio; // le pegamos antes clickArea = CCRectMake(winSize.width*2, winSize.height*2, 0, 0); // afuera de la pantalla! } j2 = new Jugador(area, clickArea, this, callfuncO_selector(Jugar::golpearJ2), "stay2.png", "jump2.png", "hit21.png", "hit23.png", "hit24.png"); this->addChild(j1, 1); this->addChild(j2, 1); CCSize spriteJugador = j1->getContentSize(); CCPoint posicionJugador = ccp(spriteJugador.width/2.0, spriteJugador.height/2.0 + piso-10); j1->setPosition(posicionJugador); posicionJugador.x = winSize.width - posicionJugador.x; j2->setPosition(posicionJugador); setTouchEnabled(true); set = 1; scorePlayer1 = 0; scorePlayer2 = 0; bRet = true; bola = new Bola(piso,this, callfuncO_selector(Jugar::ResultadoJugada)); this->addChild(bola, 1); point = Point::create(); this->addChild(point, 2); win = Win::create(); this->addChild(win, 3); } while (0); return bRet; }
void Zombie::spriteMoveFinished(CCNode* sender) { CCSpriteBatchNode *sheet = (CCSpriteBatchNode *) sender; sheet->setVisible(false); }
void StoryWorld::avgGame(void) { CCLabelTTF* myDialog = (CCLabelTTF *)getChildByTag(100); CCLabelTTF* myName = (CCLabelTTF *)getChildByTag(101); CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102); CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1); CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2); strcpy(dialog, reader.GetNextDialog().c_str()); char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"}; myName->setString(theName[dialog[0]-48]); characterPasterSwitchCase(dialog[0]); switch (dialog[2]) { case '1': { setTouchEnabled(false); CCSprite *back = CCSprite::create(LANDSCAPE_IMG_PATH); back->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); back->setOpacity(150); back->setTag(3); addChild(back, 3); switch (current) { case '3': { CCLabelTTF *Label1 = CCLabelTTF::create("Yes", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("No", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::leafletChoiceHandler)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::leafletChoiceHandler)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; case '9': { CCLabelTTF *Label1 = CCLabelTTF::create("子轩", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("少杰", "Heiti SC", 40); CCLabelTTF *Label3 = CCLabelTTF::create("建国", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::theFinalChoiceHandler)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::theFinalChoiceHandler)); CCMenuItemLabel *thirdChoice = CCMenuItemLabel::create(Label3, this, menu_selector(StoryWorld::theFinalChoiceHandler)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); thirdChoice->setTag(tChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); thirdChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 1.8)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, thirdChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; default: break; } } break; case '2': { } break; case '3': { if (myLeftSprite->getOpacity() == 0) myLeftSprite->setOpacity(255); else myLeftSprite->runAction(CCFadeOut::create(1)); } break; case '4': { if (myRightSprite->getOpacity() == 0) myRightSprite->setOpacity(255); else myRightSprite->runAction(CCFadeOut::create(1)); } break; case '5': { if (myRightSprite->getOpacity()==0 && myLeftSprite->getOpacity()==0) { myLeftSprite->setOpacity(255); myRightSprite->setOpacity(255); } else if (myRightSprite->getOpacity()!=0 && myLeftSprite->getOpacity()!=0) { myLeftSprite->runAction(CCFadeOut::create(1)); myRightSprite->runAction(CCFadeOut::create(1)); } } break; default: break; } specialPartSwitchCase(dialog[3]); audioSwitchCase(dialog[4]); char all_bg[8][4] = {"010", "030", "204", "701", "717", "725", "732"}; char bg_num[4]="000"; int curLine = reader.getCurLine(); sprintf(bg_num, "%c%02d", current, curLine); if (curLine == 0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]=BGNAME_IMG_PATH; bg_name[BGNAME_PATH_LEN] = current; Background->setTexture(GET_TEXTURE(bg_name)); } else { for (int i =0; i<8; i++) { if (strcmp(all_bg[i], bg_num)==0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]=""; sprintf(bg_name, BGNAME_IMG_PATH, bg_num); Background->setTexture(GET_TEXTURE(bg_name)); } } } myDialog->setString(dialog+5); }
void StoryWorld::characterPasterSwitchCase(int code) { CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102); CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1); CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2); switch (dialog[0]) { case '0': { //无人 char b[10]="me_ .png"; b[3] = dialog[1]+1; myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '1': { //ME char b[10]="me_ .png"; b[3] = dialog[1]+1; myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '2': { //子轩 char b[10]="zx_ .png"; b[3] = dialog[1]+1; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '3': { //少杰 char b[10]="sj_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '4': { //建国 char b[10]="jg_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '5': { char b[10]="la_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '6': { char b[10]="lb_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '7': { char b[10]="lc_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '8': { char b[10]="yy_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '9': { char b[10]="jj_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; default: break; } }
bool StoryWorld::init() { if ( !CCLayer::init() ) { return false; } char theName[10][11]={"","穆婧:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"}; char play[20] = SCRIPT_PATH; current=sGlobal->mapState->storyCnt+'0'; play[SCRIPT_PATH_LEN] = current; reader.ReadFileWithFullPath(CCFileUtils::sharedFileUtils()->fullPathForFilename(play)); this->setTouchEnabled(true); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); char bg_name[30] = "" ; char bg_num[4]=""; sprintf(bg_num, "%c00", current); sprintf(bg_name, BGNAME_IMG_PATH, bg_num); CCSprite *pBackground = CCSprite::createWithTexture(GET_TEXTURE(bg_name)); //CCSprite* pBackground = CCSprite::create(bg_name); pBackground->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); pBackground->setScale(1); pBackground->setTag(108); addChild(pBackground, 0); CCSprite* dialogBox = CCSprite::create(DUIHUAKUANG_IMG_PATH); dialogBox->setPosition(ccp(visibleSize.width/2, dialogBox->getContentSize().height/2)); dialogBox->setOpacity(220); addChild(dialogBox,1); CCLabelTTF* pName = CCLabelTTF::create(theName[0], "Heiti SC", 40); pName->setTag(101); pName->setPosition(ccp(pName->getContentSize().width/2, dialogBox->getContentSize().height - 2 * pName->getContentSize().height)); pName->setAnchorPoint(CCPointZero); addChild(pName, 1); CCLabelTTF* pLabel = CCLabelTTF::create("Click to Start", "Heiti SC", 40); pLabel->setTag(100); pLabel->setPosition(ccp(40, origin.y + dialogBox->getContentSize().height - 3.4 * pLabel->getContentSize().height)); pLabel->setAnchorPoint(CCPointZero); pLabel->setDimensions(CCSizeMake(1100, 0)); pLabel->setHorizontalAlignment(kCCTextAlignmentLeft); addChild(pLabel, 1); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(PLIST_IMG_PATH); CCSpriteBatchNode *spriteBatch = CCSpriteBatchNode::createWithTexture(GET_TEXTURE(VDRAWING_IMG_PATH)); spriteBatch->setTag(102); addChild(spriteBatch, 0); spriteBatch->setPosition(CCPointZero); CCSprite *leftSprite=CCSprite::createWithSpriteFrameName("me_1.png"); leftSprite->setScale(0.8); leftSprite->setPosition(ccp(leftSprite->getContentSize().width*0.6, leftSprite->getContentSize().height/2 *0.8)); leftSprite->setTag(1); leftSprite->setOpacity(0); spriteBatch->addChild(leftSprite, 0); CCSprite *rightSprite=CCSprite::createWithSpriteFrameName("blank.png"); //rightSprite->setScale(0.8); rightSprite->setPosition(ccp(800, 130)); rightSprite->setTag(2); rightSprite->setOpacity(0); spriteBatch->addChild(rightSprite, 0); avgGame(); return true; }
void GameLayer::update(float dt) { CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite *playerSprite = (CCSprite *)this->getChildByTag(PlayerTag); CCPoint currentPos = playerSprite->getPosition(); // update run distance runDistance += (currentPos.y - prevPos.y); // stay the player at specified position if (currentPos.y > kPlayerStayAtScreenPosY) { CCPoint newPos = ccp(currentPos.x, kPlayerStayAtScreenPosY); CCPoint diff = ccpSub(newPos, currentPos); // move the player and map playerSprite->setPosition(newPos); // move map nodes for (int i = 0; i < kGameMapCount; i ++) { CCNode *mapNode = this->getChildByTag(MapStartTag + i); CCPoint mapPos = ccpAdd(mapNode->getPosition(), diff); mapNode->setPosition(mapPos); // if map get out of scene if (mapPos.y <= -winSize.height) { mapPos = ccp(mapPos.x, (kGameMapCount - 1) * winSize.height); mapNode->setPosition(mapPos); this->resetMapNode(mapNode); } } // move map barrier node for (int i = 0; i < kGameMapCount; i ++) { CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i); CCPoint barrierPos = ccpAdd(barrierNode->getPosition(), diff); barrierNode->setPosition(barrierPos); // if map get out of scene if (barrierPos.y <= -winSize.height) { barrierPos = ccp(barrierPos.x, (kGameMapCount - 1) * winSize.height); barrierNode->setPosition(barrierPos); this->resetBarrierNode(barrierNode, MapBarrierStartTag + i); } } } // save current pos prevPos = playerSprite->getPosition(); // collision detection for (int i = 0; i < kGameMapCount; i ++) { CCNode *mapNode = this->getChildByTag(MapStartTag + i); CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)mapNode->getChildByTag(MapBatchNodeTag); CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition())); CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height); CCSprite *monsterSprite = (CCSprite *)batchNode->getChildByTag(MapMonsterTag); if (playerBox.intersectsRect(monsterSprite->boundingBox())) { // game over this->gameOver(); } CCSprite *riverSprite = (CCSprite *)batchNode->getChildByTag(MapRiverTag); if (playerBox.intersectsRect(riverSprite->boundingBox())) { // not in jumpping if (!isJumpping) { // game over this->gameOver(); } } for (int i = 0; i < kGameCoinCount; i ++) { CCSprite *coinSprite = (CCSprite *)batchNode->getChildByTag(MapCoinStartTag + i); if (playerBox.intersectsRect(coinSprite->boundingBox())) { coinSprite->setVisible(false); coinCount ++; } } } for (int i = 0; i < kGameMapCount; i ++) { CCNode *barrierNode = this->getChildByTag(MapBarrierStartTag + i); CCSpriteBatchNode *batchNode = (CCSpriteBatchNode *)barrierNode->getChildByTag(MapBatchNodeTag); CCPoint playerPos = batchNode->convertToNodeSpace(this->convertToWorldSpace(playerSprite->getPosition())); CCRect playerBox = CCRect(-playerSprite->getContentSize().width/2.0f + playerPos.x, -playerSprite->getContentSize().height/2.0f + playerPos.y, playerSprite->getContentSize().width, playerSprite->getContentSize().height); CCSprite *barrierSprite = (CCSprite *)batchNode->getChildByTag(MapBarrierTag); if (playerBox.intersectsRect(barrierSprite->boundingBox())) { if (!isSliding) { // game over this->gameOver(); } } } // update score label CCLabelTTF *scoreLabel = (CCLabelTTF *)this->getChildByTag(ScoreLabelTag); int totalScore = runDistance + coinCount; scoreLabel->setString(CCString::createWithFormat("score: %d", totalScore)->getCString()); }
// 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; }
// ************************************************************************************************* // Layer Init // ************************************************************************************************* // on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } this->setIsTouchEnabled(true); this->setIsKeypadEnabled(true); Depth = 0; // LayerColor 初始化 this->initWithColor(ccc4f(0,0,0,150)); this->setContentSize(CCSizeMake(WorkSize_W, WorkSize_H)); this->setIsVisible(true); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Common.plist"); CCSpriteBatchNode *spriteCommon = CCSpriteBatchNode::batchNodeWithFile("Common.png"); spriteCommon->getTextureAtlas()->resizeCapacity(50); addChild(spriteCommon); ///////////////////////////// // 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::itemFromNormalImage( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback) ); pCloseItem->setPosition( ccp(WorkSize_W - 20, 20) ); CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL); pMenu->setPosition( CCPointZero ); this->addChild(pMenu); CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 50); pLabel->setPosition( ccp(WorkSize_W/ 2, WorkSize_H - 20) ); this->addChild(pLabel); // 商店進入鈕 CCMenuItemImage *StoreItem = CCMenuItemImage::itemFromNormalImage( "HelloWorld.png", "HelloWorld.png", this, menu_selector(HelloWorld::StoreButtonCallback)); StoreItem->setPosition( ccp(WorkSize_W/2, WorkSize_H/2) ); StoreMenu = CCMenu::menuWithItems(StoreItem, NULL); StoreMenu->setPosition( CCPointZero ); this->addChild(StoreMenu); // 商店介面 spriteStoreBG = CCSprite::spriteWithSpriteFrameName("ui_shop_01.png"); spriteStoreBG->setPosition(fcp(Rectx, Recty)); spriteStoreBG->setIsVisible(false); this->addChild(spriteStoreBG, Depth++); // 商店離開鈕 CCMenuItem *StoreExitItem = CCMenuItemSprite::itemFromNormalSprite( CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), CCSprite::spriteWithSpriteFrameName("ui_shop_04.png"), this, menu_selector(HelloWorld::StoreExitBtnCallback)); CCMenu *StoreExitMenu = CCMenu::menuWithItem(StoreExitItem); StoreExitMenu->setPosition(ccp(StoreExitx, StoreExity)); spriteStoreBG->addChild(StoreExitMenu); // 準備商店項目素材 frameStoreItems[0] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_02.png"); // 金幣 frameStoreItems[1] = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("ui_shop_03.png"); // 籌碼 // 商店項目 for(int a = 0; a < MAX_IAP_NUM; a++) { // 商品項目 spriteStoreItems[a] = CCSprite::spriteWithSpriteFrame(frameStoreItems[0]); spriteStoreItems[a]->setPosition(ccp(StoreItemx[a], StoreItemy[a])); spriteStoreItems[a]->setOpacity(255); spriteStoreItems[a]->setIsVisible(false); spriteStoreBG->addChild(spriteStoreItems[a], a); // 商品內容 labelItemContent[a] = CCLabelTTF::labelWithString("------", "arial", ItemContentFrontSize); labelItemContent[a]->setColor(ccWHITE); labelItemContent[a]->setPosition(ccp(ItemContentx[a],ItemContenty[a])); spriteStoreItems[a]->addChild(labelItemContent[a]); // 商項目購買金額初始化 labelItemPrice[a] = CCLabelTTF::labelWithString("------", "arial", ItemPriceFrontSize); labelItemPrice[a]->setColor(ccWHITE); labelItemPrice[a]->setPosition(ccp(ItemPricex[a],ItemPricey[a])); spriteStoreItems[a]->addChild(labelItemPrice[a]); } // 商店Loading背景 spriteLoadingBG = CCSprite::spriteWithSpriteFrameName("loading10.png"); spriteLoadingBG->setPosition(fcp(LoadingBGx, LoadingBGy)); spriteLoadingBG->setIsVisible(false); spriteLoadingBG->setScale(0.3f); this->addChild(spriteLoadingBG, Depth++); // 商店Loading背景動畫 spriteLoadingBG->runAction(CCRepeatForever::actionWithAction(CCRotateBy::actionWithDuration(1.0f, 360.0f))); // 商店Loading文字(讀取中...) spriteLoading = CCSprite::spriteWithSpriteFrameName("loading01.png"); spriteLoading->setPosition(fcp(Loadingx, Loadingy)); spriteLoading->setIsVisible(false); this->addChild(spriteLoading, Depth++); // 商店Loading文字字(讀取中...)動畫 CCAnimation* animation = CCAnimation::animation(); animation->setDelay(0.1f); for(int a = 0; a < 8; a++) { a < 1 ? sprintf(ResourceName, "loading%02d.png", 1): sprintf(ResourceName, "loading%02d.png", a); animation->addFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(ResourceName)); spriteLoading->runAction(CCRepeatForever::actionWithAction(CCAnimate::actionWithAnimation(animation, true))); } return true; }
bool ComicScene::init() { if ( !CCLayer::init() ) { return false; } this->setIsKeypadEnabled(true); CCDirector::sharedDirector()->resume(); this->touchEnabled=true; this->currentPage = 0; this->cleanAfterExit = false; CCSpriteBatchNode* batch = new CCSpriteBatchNode(); batch->initWithTexture(CCTextureCache::sharedTextureCache()->textureForKey(Config::sharedConfig()->COMIC_PNG.c_str()), 6); this->addChild(batch, 0, BATCH_COMIC_INTRO_TAG); CCSprite* gSettingBackground = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_BG.c_str()); gSettingBackground->setPosition(Geometry::getScreenCenter()); this->addChild(gSettingBackground, 0); CCLabelBMFont* labelTouch = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_CONTINUE.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); labelTouch->setColor(ccc3(50,50,50)); labelTouch->setScale(0.7); labelTouch->setPosition( CCPoint(Geometry::getScreenBotomCenter(24)) ); this->addChild(labelTouch, 2, 100); if(!SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying() && SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() > 0) { SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::fullPathFromRelativePath(MUSIC_LEVEL2.c_str()), true); } CCSprite* sPage1; CCSprite* sPage2; CCSprite* sPage3; CCLabelBMFont* sText1; CCLabelBMFont* sText2; CCLabelBMFont* sText3; if (sequence == 1) { sPage1 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_1.c_str()); sPage1->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_A)) ); sPage1->setOpacity(0); this->addChild(sPage1, 1, 1); sText1 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_1.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); sText1->setColor(ccc3(45,0,0)); sText1->setPosition( CCPoint(Geometry::getScreenUpCenter(-Config::sharedConfig()->COMIC_ADJUST_TXT_A)) ); this->addChild(sText1, 1, 2); sPage2 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_2.c_str()); sPage2->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_B)) ); sPage2->setOpacity(0); this->addChild(sPage2, 1, 3); sText2 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_2.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); sText2->setColor(ccc3(45,0,0)); sText2->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(-Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_C)) ); this->addChild(sText2, 1, 4); sPage3 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_3.c_str()); sPage3->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_C)) ); sPage3->setOpacity(0); this->addChild(sPage3, 1, 5); sText3 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_3.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); sText3->setColor(ccc3(45,0,0)); sText3->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_C)) ); this->addChild(sText3, 1, 6); this->totalPages = 3; } else if (sequence == 2) { sPage1 = CCSprite::spriteWithSpriteFrameName(COMIC_END_1.c_str()); sPage1->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_A)) ); sPage1->setOpacity(0); this->addChild(sPage1, 1, 1); sText1 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_4.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); sText1->setColor(ccc3(45,0,0)); sText1->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(-Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_A)) ); this->addChild(sText1, 1, 2); sPage2 = CCSprite::spriteWithSpriteFrameName(COMIC_END_2.c_str()); sPage2->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_E)) ); sPage2->setOpacity(0); this->addChild(sPage2, 1, 3); sText2 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_5.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str()); sText2->setColor(ccc3(45,0,0)); sText2->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_E)) ); this->addChild(sText2, 1, 4); this->totalPages = 2; } showCurrentPage(); CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true); //ipad fix if(CCDirector::sharedDirector()->getWinSizeInPixels().width >= 768) { Border* border = new Border(); this->addChild(border, 999); } return true; }
bool GameLayer::init(void) { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); // 游戏场景背景图 CCSprite *bg = CCSprite::spriteWithFile("Space.png"); CC_BREAK_IF(!bg); bg->setAnchorPoint(CCPointZero); // 为了突出游戏场景中的精灵,将背景色彩变淡 bg->setOpacity(100); this->addChild(bg, 0, 1); // 使用位图字体显示游戏时间 CCLabelBMFont* lbScore = CCLabelBMFont::labelWithString("Time: 0", "font09.fnt"); CC_BREAK_IF(!lbScore); lbScore->setAnchorPoint(ccp(1, 1)); lbScore->setScale(0.6f); this->addChild(lbScore, 1, 3); lbScore->setPosition(ccp(310, 450)); // 载入飞船图像集 CCSpriteBatchNode* mgr = CCSpriteBatchNode::batchNodeWithFile("flight.png", 5); CC_BREAK_IF(!mgr); this->addChild(mgr, 0, 4); // 在状态栏显示一个飞船的图标 CCSprite* sprite = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30)); CC_BREAK_IF(!sprite); mgr->addChild(sprite, 1, 5); sprite->setScale(1.1f); sprite->setAnchorPoint(ccp(0, 1)); sprite->setPosition(ccp(10, 460)); // 显示当前飞船生命条数 CCLabelBMFont* lbLife = CCLabelBMFont::labelWithString("3", "font09.fnt"); CC_BREAK_IF(!lbLife); lbLife->setAnchorPoint(ccp(0, 1)); lbLife->setScale(0.6f); this->addChild(lbLife, 1, 6); lbLife->setPosition(ccp(50, 450)); // 设定时间回调函数,修改游戏用时显示 this->schedule(schedule_selector(GameLayer::step), 1.0f); // 显示飞船,飞船有不断闪烁的火焰喷射效果 flight = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30)); CC_BREAK_IF(!flight); flight->setPosition(ccp(160, 30)); flight->setScale(1.6f); mgr->addChild(flight, 1, 99); // 设定动画每一帧的内容 CCAnimation* animation = CCAnimation::animation(); CC_BREAK_IF(!animation); animation->setName("flight"); animation->setDelayPerUnit(0.2f); for (int i = 0; i < 3; ++i) { int x = i % 3; animation->addSpriteFrameWithTexture(mgr->getTexture(), CCRectMake(x*32, 0, 31, 30)); } // 基于动画创建动作 CCAnimate* action = CCAnimate::actionWithAnimation(animation); CC_BREAK_IF(!action); // 主角精灵不断重复动作,实现动态飞行效果 flight->runAction(CCRepeatForever::actionWithAction(action)); // accept touch now this->setTouchEnabled(true); bRet = true; } while (false); return bRet; }
void CMO_line::update( float delta ) { if ( !m_Connected && CGameManager::GetInstance()->IsConnected(m_Index) == MO_LINE_CONNECTED) { CAudioManager::GetInstance()->PlayLineDrawRandomSE(); // 처음으로 연결되는 시점 // 이미지를 바꿔주고, 연결상태 플래그 변경 changeImage(); m_Connected = true; m_RecentConnection = true; CGameManager::GetInstance()->SetRecentConnectedLine(m_Index); // 애니메이션 관련 CCSpriteBatchNode* spritebatch = CCSpriteBatchNode::create(LineAnimationFileList[m_ImageFileIdx % 2].c_str()); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile(LineAnimationFileListPlist[m_ImageFileIdx % 2].c_str()); CCArray* animFrames = CCArray::createWithCapacity(48); char str[100] = {0}; for(int i = 1; i < 49; i++) { if(m_ImageFileIdx % 2==0) { sprintf(str, "ani_playscene_line_recent_v_000%02d.png", i); } else { sprintf(str, "ani_playscene_line_recent_000%02d.png", i); } CCSpriteFrame* frame = cache->spriteFrameByName( str ); animFrames->addObject(frame); } // 최근 연결 라인 강조 관련 CCSprite*pElement; if(m_ImageFileIdx % 2==0) { pElement = CCSprite::createWithSpriteFrameName("ani_playscene_line_recent_v_00001.png"); pElement->setAnchorPoint(ccp(1,0)); } else { pElement = CCSprite::createWithSpriteFrameName("ani_playscene_line_recent_00001.png"); pElement->setAnchorPoint(ccp(0,0)); } // 강조하는 라인으로 기존 라인을 덮어버림 ?? spritebatch->addChild(pElement); addChild(spritebatch,2); spritebatch->setTag(0); // 애니메이션 재생 CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames,PLAYSCENE_ANIMATION_TIME/48); CCAction* myLine = CCAnimate::create(animation); pElement->runAction(myLine); } else if( m_Connected && m_RecentConnection && !(CGameManager::GetInstance()->GetRecentConnectedLine() == m_Index) ) { // 연결된 상태 + 강조된 상태 + 하지만 실제로 최근어 그어진 라인은 다른 라인 = 강조 상태 되돌리기 // 업데이트가 있어야만 진입하므로 실제로는 다른 선이 새로 그어질 때 호출 m_RecentConnection = false; removeChildByTag(0); pLine->setVisible(true); } }
bool GameMain::init(){ if(!CCLayer::init()){ return false; } CCSpriteFrameCache* frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile((sceneDir+"mainscene1-hd.plist").c_str()); CCSpriteBatchNode* mainSceneBatch = CCSpriteBatchNode::createWithTexture(SPRITE(mainbg.png)->getTexture()); addChild(mainSceneBatch); //背景图片 CCSprite* mainBg = SPRITE(mainbg.png); CCPoint centerPoint = ccp(winSize.width/2,winSize.height/2); mainBg->setPosition(centerPoint); mainSceneBatch->addChild(mainBg); //云彩 CCSprite* cloud1 = SPRITE(cloud1.png); CCSprite* cloud2 = SPRITE(cloud2.png); cloud1->setPosition(ccp(-100,winSize.height-100)); cloud2->setPosition(ccp(-500,winSize.height-200)); CCActionInterval* cloud1Move = CCMoveTo::create(70,ccp(1700,winSize.height-100)); CCActionInterval* cloud2Move = CCMoveTo::create(70,ccp(1300,winSize.height-200)); cloud1->runAction(cloud1Move); cloud2->runAction(cloud2Move); cloud1->setColor(ccWHITE); cloud2->setColor(ccWHITE); ccBlendFunc bf = {GL_ONE, GL_ONE_MINUS_SRC_ALPHA}; mainSceneBatch->setBlendFunc(bf); cloud1->setBlendFunc(bf); cloud2->setBlendFunc(bf); mainSceneBatch->addChild(cloud1); mainSceneBatch->addChild(cloud2); carrotNode = CCNode::create(); //萝卜 CCSprite* carrot = SPRITE(carrot.png); carrot->setAnchorPoint(ccp(0.5,0)); carrot->setPosition(CCPointZero); CCPoint leafPoint = ccp(0,carrot->getContentSize().height-50); //leaf CCSprite* carrotLeaf1 = SPRITE(leaf-1.png); CCSprite* carrotLeaf2 = SPRITE(leaf-2.png); CCSprite* carrotLeaf3 = SPRITE(leaf-3.png); carrotLeaf1->setAnchorPoint(ccp(1,0)); carrotLeaf2->setAnchorPoint(ccp(0.5,0)); carrotLeaf3->setAnchorPoint(ccp(0,0)); carrotLeaf1->setPosition(leafPoint); carrotLeaf2->setPosition(leafPoint); carrotLeaf3->setPosition(leafPoint); carrotNode->addChild(carrotLeaf1); carrotNode->addChild(carrotLeaf3); carrotNode->addChild(carrotLeaf2); carrotNode->addChild(carrot); carrotNode->setPosition(ccp(centerPoint.x,centerPoint.y-50)); carrotNode->setScale(0); CCActionInterval* scaleAction = CCScaleTo::create(0.3,1,1); CCActionInterval* delayRun = CCDelayTime::create(0.3); CCSequence* carrotNodeSeq = CCSequence::create(delayRun,scaleAction,NULL); addChild(carrotNode); //Logo图片 CCSprite* mainBg_CN = SPRITE(mainbg_CN.png); mainBg_CN->setPosition(centerPoint); addChild(mainBg_CN); CCSprite* bird = SPRITE(bird.png); bird->setPosition(ccp(VisibleRect::leftTop().x+200,VisibleRect::leftTop().y-150)); CCActionInterval* birdUp = CCMoveBy::create(2,ccp(0,35)); CCActionInterval* birdDown = birdUp->reverse(); CCSequence* birdAction = CCSequence::create(birdUp,birdDown,NULL); bird->runAction(CCRepeatForever::create(birdAction)); mainSceneBatch->addChild(bird); //冒险模式 Boss模式 宠物窝 CCMenuItemSprite* adventureMode = CCMenuItemSprite::create(SPRITE(btn_adventure_normal_CN.png), SPRITE(btn_adventure_pressed_CN.png),SceneManager::shareSceneManager(),menu_selector(SceneManager::toAdventureScene)); CCMenuItemSprite* bossMode = CCMenuItemSprite::create(SPRITE(btn_boss_normal_CN.png), SPRITE(btn_boss_pressed_CN.png)); CCMenuItemSprite* nest = CCMenuItemSprite::create(SPRITE(btn_nest_normal_CN.png), SPRITE(btn_nest_pressed_CN.png)); CCMenu* mainMenu = CCMenu::create(adventureMode,bossMode,nest,NULL); mainMenu->alignItemsHorizontallyWithPadding(20); mainMenu->setPosition(ccp(VisibleRect::center().x,VisibleRect::bottom().y+100)); addChild(mainMenu); //设置和帮助菜单 CCMenuItemSprite* settingBtn = CCMenuItemSprite::create(SPRITE(btn_setting_normal.png),SPRITE(btn_setting_pressed.png), SceneManager::shareSceneManager(),menu_selector(SceneManager::toSettingScene)); CCMenuItemSprite* helpBtn = CCMenuItemSprite::create(SPRITE(btn_help_normal.png),SPRITE(btn_help_pressed.png), SceneManager::shareSceneManager(),menu_selector(SceneManager::toHelpScene)); CCMenu* setMenu = CCMenu::create(settingBtn,helpBtn,NULL); setMenu->alignItemsHorizontallyWithPadding(450); setMenu->setPosition(ccp(VisibleRect::center().x,VisibleRect::center().y-95)); addChild(setMenu); //萝卜叶子的动画 CCActionInterval* shake = CCRotateBy::create(0.1,10); CCActionInterval* shakeBack = shake->reverse(); CCActionInterval* nextDelay = CCDelayTime::create(3); CCActionInterval* repeatDelay = CCDelayTime::create(1); CCCallFunc* callBack = CCCallFunc::create(this,callfunc_selector(GameMain::shakeLeaf)); CCSequence* shakeSeq = CCSequence::create(shake,shakeBack,shake,shakeBack,nextDelay,callBack,repeatDelay,NULL); carrotLeaf2->setTag(kLeaf2); carrotNode->runAction(carrotNodeSeq); carrotLeaf3->runAction(CCRepeatForever::create(shakeSeq)); return true; }
// on "init" you need to initialize your instance bool MainGame::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } _visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto bg = cocos2d::LayerColor::create(Color4B(255, 255, 255, 255)); this->addChild(bg, 0); CCSpriteBatchNode *batchNodeLine = CCSpriteBatchNode::create("line.png", 2000); _itemBatch = CCSpriteBatchNode::create("x.png", 2000); _dataBoardGame = new CELL_VALUE*[GAME_MATRIX_SIZE]; for (int i = 0;i < GAME_MATRIX_SIZE;i++) { _dataBoardGame[i] = new CELL_VALUE[GAME_MATRIX_SIZE]; for (int j = 0;j < GAME_MATRIX_SIZE;j++) { _dataBoardGame[i][j] = CELL_VALUE::UNSET; } } int numLineEachRow = GAME_MATRIX_SIZE*GAME_CELL_SIZE /_lineWidth + 1; //TODO get size int numLineCol = GAME_MATRIX_SIZE; _lineMatrixLenght = numLineEachRow*GAME_MATRIX_SIZE * 2; _lineMatrix = new cocos2d::Sprite*[_lineMatrixLenght]; _startLocationX = -(GAME_MATRIX_SIZE*GAME_CELL_SIZE - _visibleSize.width) / 2; _startLocationY = (GAME_MATRIX_SIZE*GAME_CELL_SIZE - _visibleSize.height) / 2 + _visibleSize.height; // Horizontal for (int i = 0;i < GAME_MATRIX_SIZE;i++) { for (int j = 0;j < numLineEachRow;j++) { _lineMatrix[i*numLineEachRow + j] = cocos2d::Sprite::createWithTexture(batchNodeLine->getTexture()); _lineMatrix[i*numLineEachRow + j]->setAnchorPoint(Vec2(0, 0)); _lineMatrix[i*numLineEachRow + j]->setPosition(_startLocationX+j*_lineWidth, _startLocationY-i*GAME_CELL_SIZE); this->addChild(_lineMatrix[i*numLineEachRow + j]); } } // Vertical for (int i = 0;i < GAME_MATRIX_SIZE;i++) { for (int j = 0;j < numLineEachRow;j++) { _lineMatrix[GAME_MATRIX_SIZE*numLineEachRow + i*numLineEachRow + j] = cocos2d::Sprite::createWithTexture(batchNodeLine->getTexture()); _lineMatrix[GAME_MATRIX_SIZE*numLineEachRow + i*numLineEachRow + j]->setAnchorPoint(Vec2(0, 0)); _lineMatrix[GAME_MATRIX_SIZE*numLineEachRow + i*numLineEachRow + j]->setRotation(90); _lineMatrix[GAME_MATRIX_SIZE*numLineEachRow + i*numLineEachRow + j]->setPosition(_startLocationX + i*GAME_CELL_SIZE, _startLocationY - j*_lineWidth); this->addChild(_lineMatrix[GAME_MATRIX_SIZE*numLineEachRow + i*numLineEachRow + j]); } } _itemMatrix = new Sprite*[GAME_MATRIX_SIZE*GAME_MATRIX_SIZE]; // Implement touch event auto singleTouchListener = EventListenerTouchOneByOne::create(); singleTouchListener->onTouchBegan = CC_CALLBACK_2(MainGame::onTouchBegan, this); singleTouchListener->onTouchMoved = CC_CALLBACK_2(MainGame::onTouchMoved, this); singleTouchListener->onTouchEnded = CC_CALLBACK_2(MainGame::onTouchEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(singleTouchListener, this); return true; }
bool ToyLayer::init() { //=================== Box2D World ======================== b2Vec2 gravity; gravity.Set(0.0F, -10.0F); this->world = new b2World(gravity); world->SetAllowSleeping(true); world->SetContinuousPhysics(true); //ToyContact *contact = new ToyContact(); //world->SetContactListener(contact); CCPoint tmp; tmp = VisibleRect::leftBottom(); b2Vec2 lb = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO); tmp = VisibleRect::rightBottom(); b2Vec2 rb = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO); tmp = VisibleRect::leftTop(); b2Vec2 lt = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO); tmp = VisibleRect::rightTop(); b2Vec2 rt = b2Vec2(tmp.x / PTM_RATIO, tmp.y / PTM_RATIO); b2BodyDef bodyDef; this->groundBody = this->world->CreateBody(&bodyDef); //World Edge b2BodyDef bd; b2Body* ground = this->world->CreateBody(&bd); { b2EdgeShape shape; shape.Set(lb, rb); ground->CreateFixture(&shape, 0.0f); } { b2EdgeShape shape; shape.Set(lt, rt); ground->CreateFixture(&shape, 0.0f); } { b2EdgeShape shape; shape.Set(lb, lt); ground->CreateFixture(&shape, 0.0f); } { b2EdgeShape shape; shape.Set(rb, rt); ground->CreateFixture(&shape, 0.0f); } //enable this->setTouchEnabled( true ); this->setAccelerometerEnabled( true ); //=================== Others ======================= this->toyArray = CCArray::create(); this->toyArray->retain(); //CCSpriteBatchNode *boxBatch = CCSpriteBatchNode::create("Images/blocks.png", 100); CCSpriteBatchNode *boxBatch = CCSpriteBatchNode::create("Images/ToyBrick/Triangle/1.png", 100); boxBatch->setTag(1); this->addChild(boxBatch, 0); this->boxTexture = boxBatch->getTexture(); //init this->AddRandomToyBrick(ccp(200, 200)); this->AddRandomToyBrick(ccp(300, 300)); this->AddRandomToyBrick(ccp(500, 500)); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //Menu -Close CCMenuItemImage *closeItem = CCMenuItemImage::create( "close.png", "close.png", this, menu_selector(ToyLayer::Back)); closeItem->setAnchorPoint(CCPointZero); closeItem->setScale(2); CCSize itemSize = closeItem->getContentSize(); closeItem->setPosition(winSize.width - (itemSize.width + 15) * 2, winSize.height - (itemSize.height + 15) * 2); CCMenu* menu = CCMenu::create(closeItem, NULL); menu->setPosition(0, 0); this->addChild(menu); //=================== Common Setting ===================== scheduleUpdate(); return true; }
void StoryWorld::avgGame(void) { CCLabelTTF* myDialog = (CCLabelTTF *)getChildByTag(100); CCLabelTTF* myName = (CCLabelTTF *)getChildByTag(101); CCSpriteBatchNode *spriteBatch = (CCSpriteBatchNode *)getChildByTag(102); CCSprite *myLeftSprite = (CCSprite *)spriteBatch->getChildByTag(1); CCSprite *myRightSprite = (CCSprite *)spriteBatch->getChildByTag(2); strcpy(dialog, reader.GetNextDialog().c_str()); char theName[10][11]={"","穆婧1:", "子轩:", "少杰:", "建国", "路人A:", "路人B:", "路人C:", "老爷爷:", "江姐:"}; myName->setString(theName[dialog[0]-48]); //任务立绘切换 switch (dialog[0]) { case '0': { //无人 char b[10]="me_ .png"; b[3] = dialog[1]+1; myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '1': { //ME char b[10]="me_ .png"; b[3] = dialog[1]+1; myLeftSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '2': { //子轩 char b[10]="zx_ .png"; b[3] = dialog[1]+1; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '3': { //少杰 char b[10]="sj_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '4': { //建国 char b[10]="jg_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '5': { char b[10]="la_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '6': { char b[10]="lb_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '7': { char b[10]="lc_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '8': { char b[10]="yy_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; case '9': { char b[10]="jj_ .png"; b[3] = dialog[1]; myRightSprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(b)); } break; default: break; } switch (dialog[2]) { // 选择走向 case '1': { //开始选择走向 //停止触摸 setTouchEnabled(false); CCSprite *back = CCSprite::create(LANDSCAPE_IMG_PATH); back->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); back->setOpacity(150); back->setTag(3); addChild(back, 3); switch (current) { case '3': { CCLabelTTF *Label1 = CCLabelTTF::create("Yes", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("No", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::makeAChoice)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::makeAChoice)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; case '9': { //创建CCMenu CCLabelTTF *Label1 = CCLabelTTF::create("子轩", "Heiti SC", 40); CCLabelTTF *Label2 = CCLabelTTF::create("少杰", "Heiti SC", 40); CCLabelTTF *Label3 = CCLabelTTF::create("建国", "Heiti SC", 40); CCMenuItemLabel *firstChoice = CCMenuItemLabel::create(Label1, this, menu_selector(StoryWorld::makeAChoice)); CCMenuItemLabel *secondChoice = CCMenuItemLabel::create(Label2, this, menu_selector(StoryWorld::makeAChoice)); CCMenuItemLabel *thirdChoice = CCMenuItemLabel::create(Label3, this, menu_selector(StoryWorld::makeAChoice)); firstChoice->setTag(fChoice); secondChoice->setTag(sChoice); thirdChoice->setTag(tChoice); firstChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 4.1)); secondChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 2.9)); thirdChoice->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/5 * 1.8)); CCMenu *menu = CCMenu::create(firstChoice, secondChoice, thirdChoice, NULL); menu->setPosition(CCPointZero); menu->setTag(2); addChild(menu, 3); return; } break; default: break; } } break; case '2': { CCScene *combatScene = Combat::scene(); CCDirector::sharedDirector()->pushScene(combatScene); } break; case '3': { if (myLeftSprite->getOpacity() == 0) myLeftSprite->setOpacity(255); else myLeftSprite->runAction(CCFadeOut::create(1)); } break; case '4': { if (myRightSprite->getOpacity() == 0) myRightSprite->setOpacity(255); else myRightSprite->runAction(CCFadeOut::create(1)); } break; case '5': { if (myRightSprite->getOpacity()==0 && myLeftSprite->getOpacity()==0) { myLeftSprite->setOpacity(255); myRightSprite->setOpacity(255); } else if (myRightSprite->getOpacity()!=0 && myLeftSprite->getOpacity()!=0) { myLeftSprite->runAction(CCFadeOut::create(1)); myRightSprite->runAction(CCFadeOut::create(1)); } } break; default: break; } // 剧本切换及完结及特效 switch (dialog[3]) { case '1':{ // 保存进度 current+=1; CCEGLView::sharedOpenGLView()->setDesignResolutionSize(672, 448, kResolutionExactFit); CCDirector::sharedDirector()->popScene(); // TODO: POP OUT } break; case '2':{ // wanjie CCSprite* staff_bg = CCSprite::create(STAFFBG_IMG_PATH); staff_bg->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2 + CCDirector::sharedDirector()->getVisibleOrigin().x, CCDirector::sharedDirector()->getVisibleSize().height/2 + CCDirector::sharedDirector()->getVisibleOrigin().y)); addChild(staff_bg, 4); CCSprite* staff = CCSprite::create(STAFF_IMG_PATH ); staff->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, -CCDirector::sharedDirector()->getVisibleSize().height/2)); addChild(staff, 5); CCActionInterval * moveTo = CCMoveTo::create(20,ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height*3/2)); CCFiniteTimeAction* sequneceAction = CCSequence::create( moveTo, CCCallFunc::create(this, callfunc_selector(StoryWorld::over)), NULL); staff->runAction(sequneceAction); } break; case '3':{ CCSprite *black = CCSprite::create(BLACK_IMG_PATH); black->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width/2, CCDirector::sharedDirector()->getVisibleSize().height/2)); black->setOpacity(0); addChild(black, 4); black->runAction(CCSequence::create(CCFadeIn::create(0.5), CCFadeOut::create(0.5), NULL)); } break; default: break; } //音效 switch (dialog[4]) { case '1': case '2': case '3': case '4': case '5': case '6':{ char musicName[7] = " .mp3"; musicName[0] = dialog[4]; if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true); } CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathForFilename(musicName).c_str()); CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::sharedFileUtils()->fullPathForFilename(musicName).c_str(), true); } break; case '7': { CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true); } break; case '8': case '9': case 'A': case 'B': case 'C': case 'D': case 'G':{ char effectName[7] = " .wav"; effectName[0] = dialog[4]; CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str()); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str()); } break; case 'E': case 'F': case 'H':{ char effectName[7] = " .mp3"; effectName[0] = dialog[4]; CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str()); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(CCFileUtils::sharedFileUtils()->fullPathForFilename(effectName).c_str()); } break; default: break; } // 背景 char all_bg[8][4] = {"010", "030", "204", "701", "717", "725", "732"}; char bg_num[4]="000"; int curLine = reader.getCurLine(); sprintf(bg_num, "%c%02d", current, curLine); if (curLine == 0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]=BGNAME_IMG_PATH; bg_name[BGNAME_PATH_LEN] = current; Background->setTexture(CCTextureCache::sharedTextureCache()->addImage(bg_name)); } else { for (int i =0; i<8; i++) { if (strcmp(all_bg[i], bg_num)==0) { CCSprite *Background = (CCSprite *)getChildByTag(108); char bg_name[30]="img/story/bg_000.jpg"; sprintf(bg_name, "img/story/bg_%s.jpg", bg_num); Background->setTexture(CCTextureCache::sharedTextureCache()->addImage(bg_name)); } } } myDialog->setString(dialog+5); }