void EasyEffect::setFadeEffect(float fTime,fadeTYPE fType) { CCLayerColor* clrLayer = (CCLayerColor*)CCDirector::sharedDirector()->getRunningScene()->getChildByTag(99); if(clrLayer == NULL) return; switch(fType) { case white_FADE_IN: { clrLayer->initWithColor(Color4B(255,255,255,255)); CCActionInterval* whtFadeOut=CCFadeTo::create(fTime,0); clrLayer->runAction(whtFadeOut); break; } case white_FADE_OUT: { clrLayer->initWithColor(ccc4(255,255,255,0)); CCActionInterval* whtFadeIn=CCFadeTo::create(fTime,255); clrLayer->runAction(whtFadeIn); break; } case black_FADE_IN: { clrLayer->initWithColor(ccc4(0,0,0,255)); CCActionInterval* blkFadeOut=CCFadeTo::create(fTime,0); clrLayer->runAction(blkFadeOut); break; } case black_FADE_OUT: { clrLayer->initWithColor(ccc4(0,0,0,0)); CCActionInterval* blkFadeIn=CCFadeTo::create(fTime,255); clrLayer->runAction(blkFadeIn); break; } case black_FADE_HOLD: { clrLayer->initWithColor(ccc4(0,0,0,255)); } break; case black_FADE_OUTIN: { CCActionInterval* blkFadeOut=CCFadeTo::create(fTime,255); CCActionInterval* blkFadeIn=CCFadeTo::create(fTime,0); CCActionInterval* seq = CCSequence::create(blkFadeOut,blkFadeIn,NULL); clrLayer->runAction(seq); } break; } }
void ShowTip::show(const char *str, cocos2d::CCPoint& point, float fontSize, float delayTime, bool displayBg) { CCLabelTTF* ttfTip = CCLabelTTF::create(str, "宋体", fontSize); ttfTip->cocos2d::CCNode::setAnchorPoint(CCPoint(0, 0)); CCSize size = ttfTip->getContentSize(); CCLayerColor* bgColor = NULL; if (displayBg) { bgColor = CCLayerColor::create(); bgColor->setColor(ccColor3B(ccc3(0, 0, 0))); bgColor->setAnchorPoint(CCPoint(0.5,0.5)); bgColor->setPosition(CCPoint(point.x - size.width * 0.5, point.y - 40)); bgColor->setContentSize(size); bgColor->addChild(ttfTip); this->addChild(bgColor); ttfTip->setFontFillColor(ccColor3B(ccc3(255, 255, 255))); } else { size = CCSize(0,0); ttfTip->setFontFillColor(ccColor3B(ccc3(0, 0, 0))); ttfTip->setPosition(CCPoint(point.x, point.y - 60)); this->addChild(ttfTip); } CCAction* moveTo = CCMoveTo::create(delayTime, CCPoint(point.x - size.width * 0.5, point.y + 40)); if ( displayBg && bgColor ) { CCFadeIn* fadeIn = CCFadeIn::create(delayTime * 0.25); CCScaleTo* scaleTo = CCScaleTo::create(delayTime * 0.5, 1); CCFadeOut* fadeOut = CCFadeOut::create(delayTime * 0.25); bgColor->runAction(CCSequence::create(fadeIn,scaleTo, fadeOut, NULL)); bgColor->runAction(moveTo); } else { CCFadeIn* fadeIn = CCFadeIn::create(delayTime * 0.5); CCFadeOut* fadeOut = CCFadeOut::create(delayTime * 0.5); ttfTip->runAction(CCSequence::create(fadeIn, fadeOut, NULL)); ttfTip->runAction(moveTo); } scheduleOnce(schedule_selector(ShowTip::removeFromParent), delayTime); }
// LayerIgnoreAnchorPointScale void LayerIgnoreAnchorPointScale::onEnter() { LayerTest::onEnter(); CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLayerColor *l = CCLayerColor::create(ccc4(255, 0, 0, 255), 200, 200); l->setAnchorPoint(ccp(0.5f, 1.0f)); l->setPosition(ccp( s.width/2, s.height/2)); CCScaleBy *scale = CCScaleBy::create(2, 2); CCScaleBy* back = (CCScaleBy*)scale->reverse(); CCSequence *seq = CCSequence::create(scale, 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(LayerIgnoreAnchorPointScale::onToggle)); CCMenu *menu = CCMenu::create(item, NULL); this->addChild(menu); menu->setPosition(ccp(s.width/2, s.height/2)); }
// on "init" you need to initialize your instance bool TestCleanUp::init() { if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); float top = origin.y + visibleSize.height; CCPoint center = ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2); // ----- // title // ------- CCLabelTTF* title = CCLabelTTF::create(); title->setString("Test Clean Up"); title->setPosition(ccp(center.x, top - 50 )); addChild(title); { CCLayerColor* sprite = CCLayerColor::create(ccc4(255,0,0,255)); sprite->changeWidthAndHeight(100, 100); CCMoveBy* move = CCMoveBy::create(100, ccp(0,0)); sprite->runAction(move); // check if has memory leak } return true; }
//切换游戏地图之前 void GameScene::switchMap() { //创建一个遮罩层,用于地图切换时的显示淡入淡出效果 CCLayerColor* fadeLayer = CCLayerColor::layerWithColor(ccc4(0, 0, 0, 0)); fadeLayer->setAnchorPoint(CCPointZero); fadeLayer->setPosition(CCPointZero); addChild(fadeLayer, kFadeLayer, kFadeLayer); //执行淡入动画,结束后调用resetGameLayer方法 CCAction* action = CCSequence::actions( CCFadeIn::actionWithDuration(0.5f), CCCallFunc::actionWithTarget(this, callfunc_selector(GameScene::resetGameLayer)), NULL); fadeLayer->runAction(action); }
void End::showSlide() { CCLayerColor *colorLayer = CCLayerColor::create(ccc4(0, 0, 0, 0)); addChild(colorLayer,2); colorLayer->runAction(CCSequence::create ( CCFadeIn::create(0.6), CCCallFunc::create(this, callfunc_selector(End::loadSlide)), CCFadeOut::create(0.6), CCHide::create(), CCCallFunc::create(this, callfunc_selector(End::showSlideText)), NULL )); }
void ASBotFightLayer::LichKingBigAttack(){ CCLayerColor* layer = CCLayerColor::create(ccc4(255,255,255,255)); addChild(layer,5); CCActionInterval* fadeIn = CCFadeIn::create(0.2); CCDelayTime* delay = CCDelayTime::create(1); CCActionInterval* fadeOut = CCFadeOut::create(0.5); CCCallFunc* minusHP = CCCallFuncN::create(this, callfuncN_selector(ASBotFightLayer::LichKingMinusHP)); CCSequence* effect2 = CCSequence::create(fadeIn,delay,fadeOut,minusHP,NULL); CCDelayTime* delay1 = CCDelayTime::create(1); CCCallFunc* remove = CCCallFuncN::create(this, callfuncN_selector(ASBotFightLayer::removeSwordAndCube)); CCSequence* effect1 = CCSequence::create(delay1,remove,NULL); CCActionInterval* effect3 = CCSpawn::create(effect1,effect2,NULL); layer->runAction(effect3); CCActionInterval* shake1 = CCRotateTo::create(0.15, 30); CCActionInterval* shake2 = CCRotateTo::create(0.15, 0); CCActionInterval* shake3 = CCRotateTo::create(0.15, -30); CCActionInterval* shake4 = CCRotateTo::create(0.15, 0); CCSequence* seq1 = CCSequence::create(shake1,shake2,shake3,shake4,NULL); BotHero->runAction(seq1); }
void GameScene::gameOver() { CCRingSprite* pRing; for(std::list<int>::iterator itr = CCRingSprite::s_tags.begin(); itr != CCRingSprite::s_tags.end() ; itr++){ pRing = (CCRingSprite*)this->getChildByTag(*itr); pRing->unscheduleUpdate(); } getChildByTag(kTagBackground)->unscheduleUpdate(); m_pBattery->stopUserInput(); CCTintTo* toWhite = CCTintTo::create(2.0f,255,255,255); m_pScoreLabel->runAction(toWhite); CCLayerColor* gameOverLayer = CCLayerColor::create(ccc4(0,0,0,128),m_winSize.width,m_winSize.height); gameOverLayer->setAnchorPoint(CCPointZero); gameOverLayer->setPosition(ccp(0,m_winSize.height)); gameOverLayer->setOpacity(0); CCActionInterval* fade = CCFadeIn::create(1.0f); CCMoveTo* move = CCMoveTo::create(0.4f,CCPointZero); gameOverLayer->runAction(CCEaseSineIn::create(CCSpawn::createWithTwoActions(fade,move))); this->addChild(gameOverLayer,kZOrderGameOverLayer,kTagGameOverLayer); CCDelayTime* delay = CCDelayTime::create(0.3f); CCCallFunc* ad = CCCallFunc::create(this, callfunc_selector( GameScene::callAd) ); this->runAction(CCSequence::createWithTwoActions(delay,ad)); saveScore(); showRetryButtons(); SimpleAudioEngine::sharedEngine()->playBackgroundMusic("sounds/GameOver.mp3",false); m_gameState = kStateGameOver; }