版本效果MoonWarrior cocos2d-x版本 --1
文章结束给大家来个程序员笑话:[M]
网上似乎有这个版本了,但是人家是人家做的,自己动手敲一遍代码感觉还是不一样的
MoonWarrior cocos2d-x里头是用JS绑定来实现的,效果写的还挺好的,麻雀虽小五脏俱全,改成C++,既熟习了cocos2d-x,也复习了前段时间学的js
把win32的环境搭建好当前,新建一个cocos2d-x的工程,这篇就写Menu吧
新建一个类,继承自CCLayer,
需要写两行代码
virtual bool init();CREATE_FUNC(LoadingScene);CREATE_FUNC是个宏定义,就是实现了create的方法,而create方法会调用init方法来初始化
bool bRet = false;do{//// super init first//CC_BREAK_IF(! CCLayer::init());CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //加了两个图片进来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); //三个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)); 每日一道理天又快黑了,这座忙碌的城市又将入睡,让这劳累的“身躯”暂别白日的辛勤,让它入睡,陪伴着城市中的人们进入梦乡。当空的弯月正深情地注视着这座城市与城市中的人们,看着家家户户的灯渐渐熄灭,它在床头悄悄奏响“明月曲”……
//这个schedule是让背景的那个小飞机飞到顶端了,还能从下面接着飞//this->schedulethis->schedule(schedule_selector(LoadingSense::update), 0.1);CCTexture2D* tmp = CCTextureCache::sharedTextureCache()->addImage("ship01.png");m_pShip = CCSprite::createWithTexture(tmp,CCRectMake(0, 45, 60, 38));this->addChild(m_pShip,0,4);CCPoint pos = ccp(((float)(rand()%10)/10)*winSize.width, 0); //让飞机从底下飞到上边m_pShip->setPosition(pos);//m_pShip->setPosition(ccp(100,100));m_pShip->runAction(CCMoveBy::create(2,ccp(((float)(rand()%10)/10)*winSize.width,pos.y+winSize.height + 100)));//m_pShip->runAction(CCMoveBy::create(2,ccp(200,200))); //播放音乐if(true){CocosDenshion::SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.7);CocosDenshion::SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_mainMainMusic,true);}bRet = true;}while(0);return bRet;
转一篇关于锚点的 http://blog.csdn.net/cjopengler/article/details/7045638
基本的都有了,下面再看一个动画效果,点击new game当前,会有一个效果,看看这个效果怎么做的
CCSprite* flare = CCSprite::create("flare.jpg");ccBlendFunc ccBF = {GL_SRC_ALPHA, GL_ONE}; flare->setBlendFunc(ccBF);parent->addChild(flare, 10);flare->setOpacity(0);flare->setPosition(ccp(-30, 297));flare->setRotation(-120);flare->setScale(0.2);CCFadeTo* opacityAnim = CCFadeTo::create(0.5, 255);CCFadeTo* opacDim = CCFadeTo::create(1, 0);CCScaleBy* biggeAnim = CCScaleBy::create(0.7, 1.2, 1.2);CCEaseSineOut* biggerEase = CCEaseSineOut::create(biggeAnim);CCMoveBy* moveAnim = CCMoveBy::create(0.5, ccp(328, 0));CCEaseSineOut* easeMove = CCEaseSineOut::create(moveAnim);CCRotateBy* rotateAnim = CCRotateBy::create(2.5, 90);CCEaseExponentialOut* rotateEase = CCEaseExponentialOut::create(rotateAnim);CCScaleTo* bigger = CCScaleTo::create(0.5, 1);CCCallFunc* onComplete = CCCallFunc::create(target, callback);CCCallFunc* killflare = CCCallFunc::create(target, callfunc_selector(LoadingSense::killFlare));flare->runAction(CCSequence::create(opacityAnim, biggerEase, opacDim, killflare, onComplete,NULL));flare->runAction(easeMove);flare->runAction(rotateEase);flare->runAction(bigger);
关于cocos2d-x的动画,简单点的可以看http://blog.csdn.net/odustggg/article/details/8187843
这样背景 菜单 点击newGame以后的动画效果都就有了,后面就是该做游戏的重头戏了
文章结束给大家分享下程序员的一些笑话语录: 面试官:熟悉哪种语言
应聘者:JAVA
面试官:知道什么叫类么
应聘者:我这人实在,工作努力,不知道什么叫累
面试官:知道什么是包?
应聘者:我这人实在 平常不带包 也不用公司准备了
面试官:知道什么是接口吗?
应聘者:我这个人工作认真。从来不找借口偷懒
面试官:知道什么是继承么
应聘者:我是孤儿没什么可以继承的
面试官:知道什么叫对象么?
应聘者:知道,不过我工作努力,上进心强,暂时还没有打算找对象。
面试官:知道多态么?
应聘者:知道,我很保守的。我认为让心爱的女人为了自已一时的快乐去堕胎是不道德的行为!请问这和C#有什么关系??
--------------------------------- 原创文章 By
版本和效果
---------------------------------
总结
以上是生活随笔为你收集整理的版本效果MoonWarrior cocos2d-x版本 --1的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 我的C#文章模块代码
- 下一篇: Response.Write详细介绍