cocos2d-x的初步学习十四之坦克大战一

以后的篇幅中,我们来实现2dx版的坦克大战。。好了,我们一步步来实现,OK,我们先实现一个开始游戏这样的一个界面,然后切换到我们的游戏场景,下面直接上代码:

CCSprite *logoSprite=CCSprite::create("BattleCity.png");
    
    
    logoSprite->setPosition(ccp(wSize.width/2, wSize.height/2+100));
    
    logoSprite->setScale(2.0f);
    this->addChild(logoSprite, 1);
    
    
    //创建菜单
    CCMenuItemFont *startItem=CCMenuItemFont::create("开始游戏", this,menu_selector(HelloWorld::startGame));
    
    startItem->setPosition(ccp(wSize.width/2, wSize.height/2-100));
    startItem->setFontSizeObj(55);
    startItem->setFontNameObj("Georgia-Bold");
    
    CCMenu *pMenu = CCMenu::create(startItem, NULL);
    
    pMenu->setPosition(CCPointZero);
    
    this->addChild(pMenu, 1);

OK,就这么简单,看下效果图:

cocos2d-x的初步学习十四之坦克大战一_第1张图片


~~~~~OK,下面我们新建另一个场景类,叫GameScene,然后我们点击开始菜单,进行场景切换:

void HelloWorld::startGame()
{


    //场景转换
    CCScene *pScene = GameLayer::scene();
    
    //跳跃式动画
    CCDirector::sharedDirector()->replaceScene(CCTransitionJumpZoom::create(5.0f, pScene));

    //其他的一些特效
    
//    CCTransitionFade::transitionWithDuration(t, s);//淡出淡入,原场景淡出,新场景淡入
//    CCTransitionFade::transitionWithDuration(t, s, ccWHITE);//如果上一个的函数,带3个参数,则第三个参数就是淡出淡入的颜色
//    CCTransitionFlipX::transitionWithDuration(t, s, kOrientationLeftOver);//x轴左翻
//    CCTransitionFlipX::transitionWithDuration(t, s, kOrientationRightOver);//x轴右翻
//    CCTransitionFlipY::transitionWithDuration(t, s, kOrientationUpOver);//y轴上翻
//    CCTransitionFlipY::transitionWithDuration(t, s, kOrientationDownOver);//y轴下翻
//    CCTransitionFlipAngular::transitionWithDuration(t, s, kOrientationLeftOver);//有角度转的左翻
//    CCTransitionFlipAngular::transitionWithDuration(t, s, kOrientationRightOver);//有角度转的右翻
//    CCTransitionZoomFlipX::transitionWithDuration(t, s, kOrientationLeftOver);//带缩放效果x轴左翻
//    CCTransitionZoomFlipX::transitionWithDuration(t, s, kOrientationRightOver);//带缩放效果x轴右翻
//    CCTransitionZoomFlipY::transitionWithDuration(t, s, kOrientationUpOver);//带缩放效果y轴上翻
//    CCTransitionZoomFlipY::transitionWithDuration(t, s, kOrientationDownOver);//带缩放效果y轴下翻
//    CCTransitionZoomFlipAngular::transitionWithDuration(t, s, kOrientationLeftOver);//带缩放效果/有角度转的左翻
//    CCTransitionZoomFlipAngular::transitionWithDuration(t, s, kOrientationRightOver);//带缩放效果有角度转的右翻
//    CCTransitionShrinkGrow::transitionWithDuration(t, s);//交错换
//    CCTransitionRotoZoom::transitionWithDuration(t, s);//转角换
//    CCTransitionMoveInL::transitionWithDuration(t, s);//新场景从左移入覆盖
//    CCTransitionMoveInR::transitionWithDuration(t, s);//新场景从右移入覆盖
//    CCTransitionMoveInT::transitionWithDuration(t, s);//新场景从上移入覆盖
//    CCTransitionMoveInB::transitionWithDuration(t, s);//新场景从下移入覆盖
//    CCTransitionSlideInL::transitionWithDuration(t, s);//场景从左移入推出原场景
//    CCTransitionSlideInR::transitionWithDuration(t, s);//场景从右移入推出原场景
//    CCTransitionSlideInT::transitionWithDuration(t, s);//场景从上移入推出原场景
//    CCTransitionSlideInB::transitionWithDuration(t, s);//场景从下移入推出原场景
//    以下三个需要检测opengl版本是否支持CCConfiguration::sharedConfiguration()->getGlesVersion() <= GLES_VER_1_0如果为真则为不支持
//    CCTransitionCrossFade::transitionWithDuration(t,s);//淡出淡入交叉,同时进行
//    CCTransitionRadialCCW::transitionWithDuration(t,s);//顺时针切入
//    CCTransitionRadialCW::transitionWithDuration(t,s);//逆时针切入
//    以下两个需要先设置摄像机,使用CCDirector::sharedDirector()->setDepthTest(true);
//    CCTransitionPageTurn::transitionWithDuration(t, s, false);//翻页,前翻
//    CCTransitionPageTurn::transitionWithDuration(t, s, true);//翻页,后翻
//    CCTransitionFadeTR::transitionWithDuration(t, s);//向右上波浪
//    CCTransitionFadeBL::transitionWithDuration(t, s);//向左下波浪
//    CCTransitionFadeUp::transitionWithDuration(t, s);//向上百叶窗
//    CCTransitionFadeDown::transitionWithDuration(t, s);//向下百叶窗
//    CCTransitionTurnOffTiles::transitionWithDuration(t, s);//随机小方块
//    CCTransitionSplitRows::transitionWithDuration(t, s);//按行切
//    CCTransitionSplitCols::transitionWithDuration(t, s);//按列切
    
    
    
}

OK,切换到另一个场景

cocos2d-x的初步学习十四之坦克大战一_第2张图片


~~~~

你可能感兴趣的:(游戏,cocos2d,cocos2d-x,坦克大战)