当前位置:编程学习 > wap >>

MoonWarrior cocos2d-x版本 --1

网上好像有这个版本了,但是人家是人家做的,自己动手敲一遍代码感觉还是不一样的

MoonWarrior cocos2d-x里面是用JS绑定来实现的,效果写的还挺好的,麻雀虽小五脏俱全,改成C++,既熟悉了cocos2d-x,也复习了前段时间学的js


把win32的环境搭建好以后,新建一个cocos2d-x的工程,这篇就写Menu吧

新建一个类,继承自CCLayer,

需要写两行代码


[cpp] 
virtual bool init(); 
CREATE_FUNC(LoadingScene); 

 virtual bool init();
 CREATE_FUNC(LoadingScene);
CREATE_FUNC是个宏定义,就是实现了create的方法,而create方易做图调用init方法来初始化


[cpp] 
bool bRet = false; 
do{ 
    //////////////////////////////////////////////////////////////////////////  
    // super init first  
    //////////////////////////////////////////////////////////////////////////  
 
    CC_BREAK_IF(! CCLayer::init()); 
 
    CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 

 bool bRet = false;
 do{
  //////////////////////////////////////////////////////////////////////////
  // super init first
  //////////////////////////////////////////////////////////////////////////

  CC_BREAK_IF(! CCLayer::init());

     CCSize winSize = CCDirector::sharedDirector()->getWinSize();[cpp] view plaincopyprint?
//加了两个图片进来  
        CCSprite* background = CCSprite::create("loading.png"); 
        background->setAnchorPoint(ccp(0,0)); 
        this->addChild(background,0,1); 
 
        CCSprite* logo = CCSprite::create("logo.png"); 
        logo->setAnchorPoint(ccp(0,0)); 
        logo->setPosition(ccp(0,250)); 
        this->addChild(logo,10,1); 

//加了两个图片进来
  CCSprite* background = CCSprite::create("loading.png");
  background->setAnchorPoint(ccp(0,0));
  this->addChild(background,0,1);

  CCSprite* logo = CCSprite::create("logo.png");
  logo->setAnchorPoint(ccp(0,0));
  logo->setPosition(ccp(0,250));
  this->addChild(logo,10,1);

[cpp] 
//三个menu进来,menu也是有状态的,直接就可以生成了  
        CCSprite* newGameNormal = CCSprite::create("menu.png",CCRectMake(0, 0, 126, 33));//cc.Sprite.create(s_menu, cc.rect(0, 0, 126, 33));  
        CCSprite* newGameSelected = CCSprite::create("menu.png", CCRectMake(0, 33, 126, 33)); 
        CCSprite* newGameDisabled = CCSprite::create("menu.png", CCRectMake(0, 33 * 2, 126, 33)); 
 
        CCSprite* gameSettingsNormal = CCSprite::create("menu.png", CCRectMake(126, 0, 126, 33)); 
        CCSprite* gameSettingsSelected = CCSprite::create("menu.png", CCRectMake(126, 33, 126, 33)); 
        CCSprite* gameSettingsDisabled = CCSprite::create("menu.png", CCRectMake(126, 33 * 2, 126, 33)); 
 
        CCSprite* aboutNormal = CCSprite::create("menu.png", CCRectMake(252, 0, 126, 33)); 
        CCSprite* aboutSelected = CCSprite::create("menu.png", CCRectMake(252, 33, 126, 33)); 
        CCSprite* aboutDisabled = CCSprite::create("menu.png", CCRectMake(252, 33 * 2, 126, 33)); 
 
        CCMenuItem* newGame = CCMenuItemSprite::create(newGameNormal,newGameSelected,newGameDisabled,this, 
            menu_selector(LoadingSense::newGameCallback)); 
        CCMenuItem* gameSettings = CCMenuItemSprite::create(gameSettingsNormal,gameSettingsSelected,gameSettingsDisabled,this, 
            menu_selector(LoadingSense::onSettings)); 
        CCMenuItem* about = CCMenuItemSprite::create(aboutNormal,aboutSelected,aboutDisabled,this, 
            menu_selector(LoadingSense::onAbout));//cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this, this.onAbout);  
 
 
        CCMenu* menu = CCMenu::create(newGame,gameSettings,about,NULL); 
         
        //CCMenu::create(newGame, gameSettings, about);  
        menu->alignItemsVerticallyWithPadding(10); 
 
        this->addChild(menu, 1, 2); 
        menu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 80)); 

//三个menu进来,menu也是有状态的,直接就可以生成了
  CCSprite* newGameNormal = CCSprite::create("menu.png",CCRectMake(0, 0, 126, 33));//cc.Sprite.create(s_menu, cc.rect(0, 0, 126, 33));
  CCSprite* newGameSelected = CCSprite::create("menu.png", CCRectMake(0, 33, 126, 33));
  CCSprite* newGameDisabled = CCSprite::create("menu.png", CCRectMake(0, 33 * 2, 126, 33));

  CCSprite* gameSettingsNormal = CCSprite::create("menu.png", CCRectMake(126, 0, 126, 33));
  CCSprite* gameSettingsSelected = CCSprite::create("menu.png", CCRectMake(126, 33, 126, 33));
  CCSprite* gameSettingsDisabled = CCSprite::create("menu.png", CCRectMake(126, 33 * 2, 126, 33));

  CCSprite* aboutNormal = CCSprite::create("menu.png", CCRectMake(252, 0, 126, 33));
  CCSprite* aboutSelected = CCSprite::create("menu.png", CCRectMake(252, 33, 126, 33));
  CCSprite* aboutDisabled = CCSprite::create("menu.png", CCRectMake(252, 33 * 2, 126, 33));

  CCMenuItem* newGame = CCMenuItemSprite::create(newGameNormal,newGameSelected,newGameDisabled,this,
   menu_selector(LoadingSense::newGameCallback));
  CCMenuItem* gameSettings = CCMenuItemSprite::create(gameSettingsNormal,gameSettingsSelected,gameSettingsDisabled,this,
   menu_selector(LoadingSense::onSettings));
  CCMenuItem* about = CCMenuItemSprite::create(aboutNormal,aboutSelected,aboutDisabled,this,
   menu_selector(LoadingSense::onAbout));//cc.MenuItemSprite.create(aboutNormal, aboutSelected, aboutDisabled, this, this.onAbout);


  CCMenu* menu = CCMenu::create(newGame,gameSettings,about,NULL);
  
  //CCMenu::create(newGame, gameSettings, about);
  menu->alignItemsVerticallyWithPadding(10);

  th

补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,