void LevelManager::repeatAction(CCNode* psender) { CCDelayTime* delay = CCDelayTime::create(1); CCMoveBy* mv = CCMoveBy::create(1,ccp(100+100*CCRANDOM_0_1(),0)); CCFiniteTimeAction* seq = CCSequence::create(delay,mv,delay->copy(), mv->reverse(), NULL); psender->runAction(CCRepeatForever::create((CCActionInterval*)seq)); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)) ) { return false; } CCSprite *pBackground = CCSprite::create("Images/background.png"); pBackground->setAnchorPoint(ccp(0, 0)); CCParallaxNode *pVoidNode = CCParallaxNode::create(); pVoidNode->addChild(pBackground, 1, ccp(1.0f, 0.0f), ccp(0, 0)); CCMoveBy *go = CCMoveBy::create(4, ccp(-160, 0)); CCActionInterval *goBack = go->reverse(); CCSequence *seq = CCSequence::create(go, goBack, NULL); CCAction *act = CCRepeatForever::create(seq); pVoidNode->runAction(act); this->addChild(pVoidNode); return true; }
//------------------------------------------------------------------ // // Layer Clip // //------------------------------------------------------------------ void CommonLayerClip::onEnter() { CommonDemo::onEnter(); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); // clip layer CCSprite* flag = CCSprite::create("Images/usa_flag.jpg"); CCLayerClip* layer = CCLayerClip::create(cc4RED); layer->ignoreAnchorPointForPosition(false); layer->setContentSize(CCSizeMake(visibleSize.width / 2, flag->getContentSize().height)); layer->setPosition(ccp(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2)); addChild(layer); // add flag to clip layer flag->setAnchorPoint(ccp(0, 0.5f)); flag->setPosition(ccp(layer->getContentSize().width, layer->getContentSize().height / 2)); layer->addChild(flag); // let flag move to see clip effect CCMoveBy* move = CCMoveBy::create(5, ccp(-flag->getContentSize().width - layer->getContentSize().width, 0)); CCFiniteTimeAction* back = (CCFiniteTimeAction*)move->reverse(); CCSequence* seq = CCSequence::createWithTwoActions(move, back); flag->runAction(CCRepeatForever::create(seq)); }
void LayerIgnoreAnchorPointPos::onEnter() { LayerTest::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *l = CCLayerColor::create(ccc4(255, 0, 0, 255), 150, 150); l->setAnchorPoint(ccp(0.5f, 0.5f)); l->setPosition(ccp( s.width/2, s.height/2)); CCMoveBy *move = CCMoveBy::create(2, ccp(100,2)); CCMoveBy * back = (CCMoveBy *)move->reverse(); CCSequence *seq = CCSequence::create(move, back, NULL); l->runAction(CCRepeatForever::create(seq)); this->addChild(l, 0, kLayerIgnoreAnchorPoint); CCSprite *child = CCSprite::create("Images/grossini.png"); l->addChild(child); CCSize lsize = l->getContentSize(); child->setPosition(ccp(lsize.width/2, lsize.height/2)); CCMenuItemFont *item = CCMenuItemFont::create("Toogle ignore anchor point", this, menu_selector(LayerIgnoreAnchorPointPos::onToggle)); CCMenu *menu = CCMenu::create(item, NULL); this->addChild(menu); menu->setPosition(ccp(s.width/2, s.height/2)); }
void GameScene::pipeCreate(float dt) { randomValue = 18 + CCRANDOM_0_1() * 50; CCSprite* pipeUp = CCSprite::createWithSpriteFrameName("pipe_up.png"); pipeUp->setAnchorPoint(ccp(0.5f, 0)); pipeUp->setPosition(ccp(screenSize.width * 1.2f, -randomValue * pipeUp->getContentSize().height / 100)); addChild(pipeUp, 2); CCSprite* pipeDown = CCSprite::createWithSpriteFrameName("pipe_down.png"); pipeDown->setAnchorPoint(ccp(0.5f, 0)); pipeDown->setPosition(ccp(pipeUp->getPositionX(), pipeUp->getPositionY() + pipeUp->getContentSize().height + screenSize.height * 0.19f)); addChild(pipeDown, 2); CCMoveBy* move = CCMoveBy::create(4.0f, ccp(-1000, 0)); CCCallFuncN* call = CCCallFuncN::create(this, callfuncN_selector(GameScene::pipeUpRemove)); CCSequence* seq = CCSequence::create(move, call, NULL); pipeUp->runAction(seq); pipeUp->setUserData((void*)0); pipeArray->addObject(pipeUp); CCCallFuncN* downCall = CCCallFuncN::create(this, callfuncN_selector(GameScene::pipeDownRemove)); CCSequence* downSeq = CCSequence::create((CCActionInterval*)(move->copy()->autorelease()), downCall, NULL); pipeDown->runAction(downSeq); hitCheckArray->addObject(pipeUp); hitCheckArray->addObject(pipeDown); }
// // MoveBy // CCMoveBy* CCMoveBy::actionWithDuration(ccTime duration, const CCPoint& position) { CCMoveBy *pMoveBy = new CCMoveBy(); pMoveBy->initWithDuration(duration, position); pMoveBy->autorelease(); return pMoveBy; }
// // MoveBy // CCMoveBy* CCMoveBy::create(float duration, const CCPoint& position) { CCMoveBy *pMoveBy = new CCMoveBy(); pMoveBy->initWithDuration(duration, position); pMoveBy->autorelease(); return pMoveBy; }
// // MoveBy // CCMoveBy* CCMoveBy::actionWithDuration(cocos2d::ccTime duration, cocos2d::CGPoint position) { CCMoveBy *pMoveBy = new CCMoveBy(); pMoveBy->initWithDuration(duration, position); pMoveBy->autorelease(); return pMoveBy; }
void FlyLamaSprite::CloseMouth(float) { this->lamaBody->setTexture(CCTextureCache::sharedTextureCache()->textureForKey("pilot/lama_whole.png")); this->lamaFace->setVisible(false); this->BlinkAnimation(); CCMoveBy* move = CCMoveBy::create(0.05f, ccp(-3, 0)); this->lamaBody->runAction(move); CCMoveBy* verse = CCMoveBy::create(0.1f, ccp(6, 0)); CCSequence* pse = CCSequence::create(verse, verse->reverse(), NULL); CCRepeat* rpt = CCRepeat::create(pse, 20); this->lamaBody->runAction(rpt); }
bool MissileAttack::enable() { if (distance < 120) { CCPoint p(0, -10); CCAffineTransform transform = CCAffineTransformRotate(CCAffineTransformIdentity, angle); p = CCPointApplyAffineTransform(p, transform); CCMoveBy * move = CCMoveBy::create(0.1f, p); CCActionInterval * rev = move->reverse(); CCAction * seq = CCSequence::create(move, rev, NULL); getParent()->runAction(seq); return false; } return true; }
CCAction *SudokuActionManager::createFailInputCellAction(CCPoint pt){ CCMoveBy *acMove = CCMoveBy::create(0.2,pt); CCRotateBy *rotate = CCRotateBy::create(0.2,80.f); CCJumpBy *jump = CCJumpBy::create(0.5,ccp(0,0),25,5); CCSequence *inputCellAction = CCSequence::create(acMove,rotate, rotate->reverse(), acMove->reverse(), jump, NULL); return inputCellAction; }
CCObject* CCMoveBy::copyWithZone(CCZone *pZone) { CCZone* pNewZone = NULL; CCMoveBy* pCopy = NULL; if(pZone && pZone->m_pCopyObject) { //in case of being called at sub class pCopy = (CCMoveBy*)(pZone->m_pCopyObject); } else { pCopy = new CCMoveBy(); pZone = pNewZone = new CCZone(pCopy); } CCMoveTo::copyWithZone(pZone); pCopy->initWithDuration(m_fDuration, m_delta); CC_SAFE_DELETE(pNewZone); return pCopy; }
bool VVBookScene::init() { if ( !CCScene::init() ) return false; pageIdx = 0; winSize = CCDirector::sharedDirector()->getWinSizeInPixels(); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) if( winSize.width == 1280 && (winSize.height == 800 || winSize.height == 720) ) winSize.height = 752; #endif isActionOngoing = false; curPage = NULL; CCDelayTime * delay = CCDelayTime::actionWithDuration(0.35); CCDelayTime * delay2 = CCDelayTime::actionWithDuration(0.1); CCMoveBy *moveOut = CCMoveBy::actionWithDuration(0.35f, ccp(-winSize.width,0)); CCMoveBy *moveIn = (CCMoveBy *)moveOut->reverse(); CCPageTurn3D *turnNext = CCPageTurn3D::actionWithSize(ccg(64,64), 0.7); CCFiniteTimeAction *slideOut = CCSequence::actions(delay,moveOut,NULL); CCFiniteTimeAction *slideIn = CCSequence::actions(delay,moveIn,NULL); CCFiniteTimeAction *pageTurnNext = CCSequence::actions(delay,turnNext,NULL); CCFiniteTimeAction *pageTurnPrev = CCSequence::actions(delay,turnNext,NULL); CCFiniteTimeAction *pushToLeft = CCSequence::actions(delay2,moveOut,NULL); CCFiniteTimeAction *pushToRight = CCSequence::actions(delay2,moveIn,NULL); transActionArray = CCMutableArray<CCFiniteTimeAction*>::arrayWithObjects(slideIn,slideOut,pageTurnNext,pageTurnPrev,pushToLeft,pushToRight,NULL); transActionArray->retain(); return true; }
bool Boss::init(){ if ( !CCSprite::init() ) { return false; } this->initWithFile(s_boss_one); m_bomb = new Enemy(); m_bomb->autorelease(); m_bomb->initWithFile(s_boss_one_bomb); addChild(m_bomb,1); CCSize size = this->getContentSize(); m_bomb->setAnchorPoint(ccp(0.5,0.8)); m_bomb->setPosition(ccp(size.width/2,size.height/2)); CCDelayTime *delay = CCDelayTime::create(1); CCMoveBy *mv = CCMoveBy::create(6, ccp(300, 0)); CCFiniteTimeAction *seq = CCSequence::create(delay, mv, delay->copy(), mv->reverse(), NULL); this->runAction(CCRepeatForever::create((CCActionInterval*)seq)); this->schedule(schedule_selector(Boss::calRoat),1); childrenInit(); }
// on "init" you need to initialize your instance bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCLog(" HelloWorld init --->"); /*CCLog(" SCALE_FACTOR --->%f " , SCALE_FACTOR);*/ top_distance = SCALE_FACTOR * 16; /*CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccpAdd(VisibleRect::rightBottom(), ccp(-pCloseItem->getContentSize().width/2, pCloseItem->getContentSize().height/2))); CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1);*/ CCLabelTTF* pLabel = CCLabelTTF::create("hello cocos2d-x", "Arial", SCALE_FACTOR * 36 ); pLabel->setPosition(ccpAdd(VisibleRect::top(),ccp(0, -pLabel->getContentSize().height))); this->addChild(pLabel, 1); //载入主菜单的pic list CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("main_menu.plist", "main_menu.png"); //背景图片 CCSprite* pSprite = CCSprite::create("bg.jpg"); pSprite->setPosition(VisibleRect::center()); this->addChild(pSprite, 0); //两片树叶 //树叶1 CCSprite* pSprite_leaf1 = CCSprite::createWithSpriteFrameName("leaf1.png"); pSprite_leaf1->setPosition( ccpAdd(VisibleRect::center(), ccp(0,pSprite_leaf1->getContentSize().height/2*3)) ); this->addChild(pSprite_leaf1); pSprite_leaf1->setAnchorPoint(ccp(0.5f,0.0f)); //设置锚点为中下点 //不停摆动的动画 CCActionInterval* rotateAction1 = CCRotateBy::create(0.1f,25.0f); CCActionInterval* rotateAction2 = CCRotateTo::create(0.1f, -25.0f); CCDelayTime* sleep_rotate = CCDelayTime::create(4.0f); pSprite_leaf1->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(rotateAction1, rotateAction2,rotateAction1, rotateAction2,sleep_rotate, NULL)))); //树叶2 CCSprite* pSprite_leaf2 = CCSprite::createWithSpriteFrameName("leaf2.png"); pSprite_leaf2->setPosition( ccpAdd(VisibleRect::center(), ccp(pSprite_leaf1->getContentSize().width,pSprite_leaf1->getContentSize().height/2*3)) ); this->addChild(pSprite_leaf2); pSprite_leaf2->setAnchorPoint(ccp(0.5f,0.0f)); //设置锚点为中下点 CCDelayTime* sleep_rotate_2 = CCDelayTime::create(2.0f); pSprite_leaf2->runAction(CCRepeatForever::create((CCActionInterval*)(CCSequence::create(sleep_rotate_2,rotateAction1, rotateAction2,rotateAction1, rotateAction2,sleep_rotate_2, NULL)))); //小岛 CCSprite* pSprite_Island = CCSprite::create("island.png"); pSprite_Island->setPosition(VisibleRect::center()); this->addChild(pSprite_Island, 0); //设置选项(左) CCMenuItemSprite* pMenuItemSprite_small_left = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("small_item_normal.png"), CCSprite::createWithSpriteFrameName("small_item_pressed.png") , this, menu_selector(HelloWorld::menuCallback)); CCMenu* pSpriteMenu_small_left = CCMenu::create(pMenuItemSprite_small_left,NULL); pSpriteMenu_small_left->setPosition( ccpAdd(VisibleRect::center(),ccp( - pSprite_Island->getContentSize().width / 2 ,- pSprite_Island->getContentSize().height/3)) ); this->addChild(pSpriteMenu_small_left ,1); //帮助选项(右) CCMenuItemSprite* pMenuItemSprite_small_right = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("small_item_normal.png"), CCSprite::createWithSpriteFrameName("small_item_pressed.png") , this,menu_selector(HelloWorld::menuCallback)); CCMenu* pSpriteMenu_small_right = CCMenu::create(pMenuItemSprite_small_right,NULL); pSpriteMenu_small_right->setPosition( ccpAdd(VisibleRect::center(),ccp( pSprite_Island->getContentSize().width / 2 ,- pSprite_Island->getContentSize().height/3)) ); this->addChild(pSpriteMenu_small_right ,1); //开始游戏选项 CCMenuItemSprite* pMenuItemSprite = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("start_normal.png"), CCSprite::createWithSpriteFrameName("start_pressed.png"), this,menu_selector(HelloWorld::menuCallback)); pMenuItemSprite->setTag(MENU_ID_START); CCMenu* pSpriteMenu = CCMenu::create(pMenuItemSprite,NULL); pSpriteMenu->setPosition( ccpAdd(VisibleRect::bottom(),ccp(0,pMenuItemSprite->getContentSize().height/2*3)) ); this->addChild(pSpriteMenu ,1); //关于我们选项 CCMenuItemSprite* pMenuItemSprite_about = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("about_us_normal.png"), CCSprite::createWithSpriteFrameName("about_us_pressed.png"), this,menu_selector(HelloWorld::menuCallback)); pMenuItemSprite_about->setTag(MENU_ID_ABOUT); CCMenu* pSpriteMenu_about = CCMenu::create(pMenuItemSprite_about,NULL); pSpriteMenu_about->setPosition( ccpAdd(pSpriteMenu->getPosition(),ccp(- (pMenuItemSprite_about->getContentSize().width+(36*SCALE_FACTOR)),0 )) ); this->addChild(pSpriteMenu_about ,1); //左上角心跳选项 CCMenuItemSprite* pMenuItemSprite_heart = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("heart_normal.png"), CCSprite::createWithSpriteFrameName("heart_pressed.png") , this,menu_selector(HelloWorld::menuCallback)); CCMenu* pSpriteMenu_heart = CCMenu::create(pMenuItemSprite_heart,NULL); pSpriteMenu_heart->setPosition( ccpAdd(VisibleRect::leftTop(),ccp(pMenuItemSprite_heart->getContentSize().width / 2 + top_distance , -pMenuItemSprite_heart->getContentSize().height / 2 - top_distance)) ); this->addChild(pSpriteMenu_heart ,1); //添加跳动的动画效果 CCActionInterval* scaleAction1 = CCScaleTo::create(0.1f, 1.2f, 1.2f); CCActionInterval* scaleAction2 = CCScaleTo::create(0.1f, 1.0f, 1.0f); CCDelayTime* sleep = CCDelayTime::create(1.0f); CCActionInterval* seq = (CCActionInterval*)(CCSequence::create(scaleAction1, scaleAction2,scaleAction1, scaleAction2,sleep, NULL)); CCActionInterval* rep = CCRepeatForever::create(seq); pMenuItemSprite_heart->runAction(rep); //小飞块 CCSprite* pS_fly = CCSprite::createWithSpriteFrameName("fly.png"); pS_fly->setPosition( ccpAdd( pSpriteMenu_heart->getPosition() , ccp(pS_fly->getContentSize().width, -pS_fly->getContentSize().height*2) ) ); this->addChild(pS_fly); //添加上下来回移动的动画效果 CCMoveBy *move = CCMoveBy::create(3.5f,ccp(0,pS_fly->getContentSize().height)); pS_fly->runAction(CCRepeatForever::create(static_cast<CCSequence *>(CCSequence::create(move,move->reverse(),NULL)))); return true; }
// on "init" you need to initialize your instance bool StartMenu::init() { ////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01); // 添加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-100)); 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)); newGame->setScale(1.5f); CCMenuItemSprite* gameSetting = CCMenuItemSprite::create(gameSettingNormal, gameSettingNSelected, gameSettingDesabled, this, menu_selector(StartMenu::menuCallback)); gameSetting->setScale(1.5f); gameSetting->setTag(20); CCMenuItemSprite* about = CCMenuItemSprite::create(aboutNormal, aboutSelected, aboutDesabled, this, menu_selector(StartMenu::menuCallback)); about->setScale(1.5f); about->setTag(21); // 最后一个参数要是NULL CCMenu* menu = CCMenu::create(newGame, gameSetting, about, NULL); menu->alignItemsVerticallyWithPadding(30); 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()->textureForKey(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()&&!Config::sharedConfig()->isOptions()&&!Config::sharedConfig()->isAbout()) { SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.7); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_mainMainMusic, true); } Config::sharedConfig()->setOptions(false); Config::sharedConfig()->setAbout(false); CCSprite* fragment = CCSprite::create(); fragment->initWithFile(s_fragment); this->addChild(fragment,1000); fragment->setPosition(ccp(240,300)); CCOrbitCamera * orbit = CCOrbitCamera::create(0.3, 1, 0, 0, 360, 0, 0);//(8, 1, 0, 0, 360, 90, -45) fragment->runAction(CCRepeatForever::create(orbit)); ///////////////////////////////////////////////////////////////////////////// CCSprite *sprite = CCSprite::create(); sprite->initWithFile(s_fire); this->addChild(sprite,10); sprite->setPosition(ccp(100,200)); CCMyParticleSun *system = CCMyParticleSun::create(); sprite->addChild(system,10); CCSize size = sprite->getContentSize(); system->setPosition(ccp(size.width/2,size.height/2)); CCMoveBy *by = CCMoveBy::create(5,ccp(400,100)); CCFiniteTimeAction *seq = CCSequence::create(by, by->reverse(), NULL); sprite->runAction(CCRepeatForever::create((CCActionInterval*)seq)); /* CCTexture2D *temp = CCTextureCache::sharedTextureCache()->addImage(s_boss_one); CCTexture2D* texture = Util::getGrayTexture(temp); // create a new CCSprite to return CCSprite* s = CCSprite::create(); s->initWithTexture(texture); addChild(s,1000); s->setPosition(ccp(200,100)); */ return true; }
void GameScene::setStatus(int state){ CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); CCPoint center = ccp(screenSize.width * 0.5, screenSize.height * 0.5); GameState = state; if (state == GameReady) { // newRecord = false; pipeCount = 0; //remove pipes if have for (int i = pipesArray->count()-1; i >= 0; i--) { Pipe *pi = (Pipe*)pipesArray->objectAtIndex(i); actionNode->removeChild(pi); } pipesArray->removeAllObjects(); //score score = 0; scoreTip->setCount(score); //show stateTipReady->setOpacity(255); help->setOpacity(255); //bg CCArray *bgAnimArray = Utils::createAnimArray("bg", 2); int bgRand = 0 + rand() % (1 - 0 + 1); bg->setDisplayFrame((CCSpriteFrame *)bgAnimArray->objectAtIndex(bgRand)); //bird CCMoveBy *birdMove = CCMoveBy::create(0.5, ccp(0, 10)); CCRepeatForever *upDown = CCRepeatForever::create(CCSequence::create(birdMove, birdMove->reverse(), NULL)); upDown->setTag(ActionTagBirdUpDown); bird->runAction(upDown); bird->setInit(); bird->setPosition(ccpAdd(center, ccp(-60, 0))); bird->setRotation(0); //land CCAction *landMove = CCRepeatForever::create (CCSequence::create(CCMoveTo::create(48/SpeedLand, ccp(-48, 0)), CCMoveTo::create(0, ccp(0, 0)), NULL)); landMove->setTag(ActionTagLandMove); land->runAction(landMove); } else if (state == GameRun) { //bird cancel upDown bird->stopActionByTag(ActionTagBirdUpDown); //tip and help fade action float durFade = 0.1; CCFadeOut *fade1 = CCFadeOut::create(durFade); CCFadeOut *fade2 = (CCFadeOut*)fade1->copy(); stateTipReady->runAction(fade1); help->runAction(fade2); this->unscheduleUpdate(); this->scheduleUpdate(); this->unschedule(schedule_selector(GameScene::setPipes)); this->schedule(schedule_selector(GameScene::setPipes), (screenSize.width/2 + 30)/SpeedPipe, kCCRepeatForever, 1); } else if (state == GameEnd) { this->unscheduleUpdate(); this->unschedule(schedule_selector(GameScene::setPipes)); //pipe action for (int i = 0 ; i < pipesArray->count(); i++) { Pipe *pi = (Pipe*)pipesArray->objectAtIndex(i); //pi->stopActionByTag(ActionTagPipeMove); pi->setAniNodeMoveSpeed(ccp(0, 0)); } //land action land->stopAllActions(); //layerColor color->runAction(CCSequence::create(CCFadeIn::create(0.1), CCFadeOut::create(0.1), NULL)); //actionNode actionNode->runAction(CCShake::createWithStrength(0.5, 20, 5)); //best score int highScore = GameData::instance()->getGDHighScore(); if (score > highScore) { GameData::instance()->setGDHighScore(score); newRecord = true; } //gold GameData::instance()->setGDGold(goldCount); } }
bool MonsterLayer::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (m_status == SLEEP && !m_isMagicMatrixAvailable) return false; CCPoint touchPos = pTouch->getLocation(); CCLOG("%f,%f",touchPos.x,touchPos.y); int iMonsterCount = m_data->size(); float fScreenHeight = CCDirector::sharedDirector()->getVisibleSize().height; if (touchPos.y > fScreenHeight - TOP_BORDER_HEIGHT) { if (m_isMagicMatrixAvailable) { CCSize magicTagSize = m_magicTag->getContentSize(); CCPoint middlePoint = m_magicTag->getPosition(); if (touchPos.x > middlePoint.x - magicTagSize.width*0.5 && touchPos.x < middlePoint.x + magicTagSize.width*0.5 && touchPos.y > middlePoint.y - magicTagSize.height*0.5 && touchPos.y < middlePoint.y + magicTagSize.height*0.5) { if (m_magicPointer->getScale() != 1) m_magicPointer->setScale(1); m_magicPointer->runAction(CCFadeIn::create(0.1f)); setStatus(SPECIAL_ATTACK_PRE); return true; } } } if (m_status == WAIT_TARGET) { if (touchPos.y < PLAYER_SPRITE_HEIGHT) { this->setStatus(SLEEP); return false; } else { for (int i = 0;i<iMonsterCount;++i) { if (m_data->at(i)->getStatus() == DEAD) continue; CCSize size = this->getChildByTag(i)->getContentSize(); CCPoint middlePoint = this->getChildByTag(i)->getPosition(); float fLeftCornerX = middlePoint.x - size.width/2; if (touchPos.x > fLeftCornerX && touchPos.x < fLeftCornerX + size.width) { CCMoveBy *pMoveAction = CCMoveBy::create(0.05f,ccp(10,10)); this->getChildByTag(i)->runAction(CCRepeat::create( CCSequence::createWithTwoActions(pMoveAction,pMoveAction->reverse()),4)); this->getChildByTag(i)->runAction(CCMoveTo::create(0.05f,m_originalPos.at(i))); this->setStatus(TARGET_SELECTED); CCLOG("Target is %d",i); m_target = i; return false; } } } } else if (m_status == SPECIAL_ATTACK) { CC_ASSERT(m_bubbles); CCObject *bubble = NULL; CCLOG("All have %d bubbles",m_bubbles->count()); CCARRAY_FOREACH(m_bubbles,bubble) { CCSprite *bubbleSprite = (CCSprite*)bubble; CCPoint middlePoint = bubbleSprite->getPosition(); CCSize size = bubbleSprite->getContentSize(); if (touchPos.x > middlePoint.x-size.width*0.5 && touchPos.x < middlePoint.x+size.width*0.5 && touchPos.y > middlePoint.y-size.height*0.5 && touchPos.y < middlePoint.y+size.height*0.5) { //bubbleSprite->cleanup(); bubbleSprite->stopAllActions(); CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCAnimation *breakAnimation = CCAnimation::create(); breakAnimation->addSpriteFrame(cache->spriteFrameByName("paopao_m6")); breakAnimation->addSpriteFrame(cache->spriteFrameByName("paopao_m7")); breakAnimation->addSpriteFrame(cache->spriteFrameByName("paopao_m8")); breakAnimation->addSpriteFrame(cache->spriteFrameByName("paopao_m9")); breakAnimation->addSpriteFrame(cache->spriteFrameByName("paopao_m10")); breakAnimation->setDelayPerUnit(0.1f); breakAnimation->setLoops(1); breakAnimation->setRestoreOriginalFrame(false); bubbleSprite->runAction(CCSequence::createWithTwoActions(CCAnimate::create(breakAnimation), CCFadeOut::create(0.1f))); m_BubbleHit++; m_bubbles->removeObject(bubbleSprite,true); CCLOG("Bubble touched retain count:%u",bubbleSprite->retainCount()); //removeChild(bubbleSprite,true); float currentPercent = m_longHPBar->getPercentage(); m_longHPBar->runAction(CCProgressFromTo::create(0.1f,currentPercent,currentPercent-10.0)); break; } }
CCMoveBy* CCMoveBy::create(float duration, const CCPoint& deltaPosition){ CCMoveBy *ret = new CCMoveBy; ret->initWithDuration(duration, deltaPosition); return ret; }