1
加入场景切换效果
供场景切换的类:
CCTransitionJumpZoom CCTransitionProgressRadialCCW CCTransitionProgressRadialCW CCTransitionProgressHorizontal CCTransitionProgressVertical CCTransitionProgressInOut CCTransitionProgressOutIn CCTransitionCrossFade CCTransitionFadeTR CCTransitionFadeBL CCTransitionFadeUp CCTransitionFadeDown CCTransitionTurnOffTiles CCTransitionSplitRows CCTransitionSplitCols CCTransitionFade CCTransitionShrinkGrow CCTransitionRotoZoom CCTransitionMoveInL CCTransitionMoveInR CCTransitionMoveInT CCTransitionMoveInB CCTransitionSlideInL CCTransitionSlideInR CCTransitionSlideInT CCTransitionSlideInB |
场景切换案例:
TMenu.h |
#ifndef #define #include USING_NS_CC; class { public: static CREATE_FUNC(TMenu); bool CCMenu * void void virtual virtual }; #endif |
TMenu.cpp |
#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //供场景切换用 static CCTransitionScene * switchSceneEffect(int index,float t,CCScene *s) { switch (index) { case 0: return CCTransitionJumpZoom::create(t, s); break; case 1: return CCTransitionProgressRadialCCW::create(t, s); break; case 2: return CCTransitionProgressRadialCW::create(t, s); break; case 3: return CCTransitionProgressHorizontal::create(t, s); break; case 4: return CCTransitionProgressVertical::create(t, s); break; case 5: return CCTransitionProgressInOut::create(t, s); break; case 6: return CCTransitionProgressOutIn::create(t, s); break; case 7: return CCTransitionCrossFade::create(t, s); break; case 8: return CCTransitionCrossFade::create(t, s); break; case 9: return CCTransitionFadeTR::create(t, s); break; case 10: return CCTransitionFadeBL::create(t ,s); break; case 11: return CCTransitionFadeUp::create(t, s); break; case 12: return CCTransitionFadeDown::create(t, s); break; case 13: return CCTransitionTurnOffTiles::create(t, s); break; case 14: return CCTransitionSplitRows::create(t, s); break; case 15: return CCTransitionSplitCols::create(t, s); break; case 16: return CCTransitionFade::create(t, s); break; case 17: return CCTransitionShrinkGrow::create(t, s); break; case 18: return CCTransitionRotoZoom::create(t, s); break; case 19: return CCTransitionMoveInL::create(t, s); break; case 20: return CCTransitionMoveInR::create(t, s); break; case 21: return CCTransitionMoveInT::create(t, s); break; case 22: return CCTransitionMoveInB::create(t, s); break; case 23: return CCTransitionSlideInL::create(t, s); break; case 24: return CCTransitionSlideInR::create(t, s); break; case 25: return CCTransitionSlideInT::create(t, s); break; case 26: return CCTransitionSlideInB::create(t, s); break; } } static { "T01LayerAnchorPoint.h", "T02LayerSprite.h", "T03LayerZorder.h", "T04ColorLayer.h", "T05Coordinate.h", "T06BatchNode.h", "T07Schedule.h", "T08Touch.h", "T09Memory.h", "T10Label.h", "T11CCMenu.h", "T12UI.h", "T13Action.h", "T14Animation.h", "T15Speed.h", "T16CCFollow.h", "T17CCProgressTo.h", "T18Grid3D.h", "T19Draw.h", "T20Music.h", "T21Particle.h", "T22UserDefault.h" }; CCScene * { CCScene * TMenu * scene->addChild(layer); return } bool { CCLayer::init(); menu = for (int { CCMenuItem * this, menu_selector(TMenu::menuCallback)); menu->addChild(item); } menu->alignItemsVertically(); addChild(menu); CCArray * array = CCObject * int CCARRAY_FOREACH(array,obj) { CCMenuItem * item->setTag(i i++; } CCMenuItem * closeItem->setTarget(this, CCMenu * menu2->setPosition(CCPointZero); closeItem->setPosition(ccp(winSize.width winSize.height addChild(menu2); setTouchEnabled(true); setTouchMode(kCCTouchesOneByOne); return } void { CCMenuItem * CCScene * switch (item->getTag()-10000) { case 1: pScene = break; case 2: pScene = break; case 3: pScene = break; case 4: pScene = break; case 5: pScene = break; case 6: pScene = break; case 7: pScene = break; case 8: pScene = break; case 9: pScene = break; case 10: pScene = break; case 11: pScene = break; case 12: pScene = break; case 13: pScene = break; case 14: pScene = break; case 15: pScene = break; case 16: pScene = break; case 17: pScene = break; case 18: pScene = break; case 19: pScene = break; case 20: pScene = break; case 21: pScene = break; case 22: pScene = break; } //以下的代码用于做控制场景切换用 if (pScene != NULL) { static int idx = 0; CCTransitionScene * scene = switchSceneEffect(idx++, 2, pScene); if (idx == 27) { idx = 0; } CCDirector::sharedDirector()->replaceScene(scene); } } void { exit(0); } bool { return } void { CCRect CCMenuItem * CCMenuItem * CCPoint CCPoint if (rcWin.containsPoint(firstInWorld)&&pTouch->getDelta().y<0) return; if (rcWin.containsPoint(lastInWorld) return; menu->setPositionY(menu->getPositionY() } |
执行效果: |
2
有时候我们想等场景切换彻底完毕之后再让动画播放,这时候须要做重写下面代码:
void void |
案例:
#include #include CCScene *T14Animation::scene() { CCScene * T14Animation * scene->addChild(layer); return } bool { TBack::init(); return } //在进入场景的时候做下面操作 void { TBack::onEnter(); //以图片的方式创建一个精灵 spr = //设置精灵的显示位置 spr->setPosition(ccp(winSize.width addChild(spr); } //当场景切换彻底完毕之后运行的动作。 void { TBack::onEnterTransitionDidFinish(); //plist中是图片信息 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("animation/plant.plist"); //创建动画 CCAnimation * //这个用于存储图片的名字 char for (int { memset(nameBuf, sprintf(nameBuf, animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(nameBuf)); } //设置每次动画运行的时候的延时 animation->setDelayPerUnit(0.1f); //这仅仅循环两次 animation->setLoops(2); CCAnimate * spr->runAction(animate); } |
上面案例在场景彻底切换完毕之后新场景中的动画等效果才运行。