版本效果MoonWarrior cocos2d-x版本 --1
文章結(jié)束給大家來個程序員笑話:[M]
????網(wǎng)上似乎有這個版本了,但是人家是人家做的,自己動手敲一遍代碼感覺還是不一樣的
????MoonWarrior cocos2d-x里頭是用JS綁定來實(shí)現(xiàn)的,效果寫的還挺好的,麻雀雖小五臟俱全,改成C++,既熟習(xí)了cocos2d-x,也復(fù)習(xí)了前段時間學(xué)的js
????把win32的環(huán)境搭建好當(dāng)前,新建一個cocos2d-x的工程,這篇就寫Menu吧
????新建一個類,繼承自CCLayer,
????需要寫兩行代碼
virtual bool init();CREATE_FUNC(LoadingScene);????CREATE_FUNC是個宏定義,就是實(shí)現(xiàn)了create的方法,而create方法會調(diào)用init方法來初始化
bool bRet = false;do{//// super init first//CC_BREAK_IF(! CCLayer::init());CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //加了兩個圖片進(jìn)來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進(jìn)來,menu也是有狀態(tài)的,直接就能夠生成了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)); 每日一道理天又快黑了,這座忙碌的城市又將入睡,讓這勞累的“身軀”暫別白日的辛勤,讓它入睡,陪伴著城市中的人們進(jìn)入夢鄉(xiāng)。當(dāng)空的彎月正深情地注視著這座城市與城市中的人們,看著家家戶戶的燈漸漸熄滅,它在床頭悄悄奏響“明月曲”……
//這個schedule是讓背景的那個小飛機(jī)飛到頂端了,還能從下面接著飛//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); //讓飛機(jī)從底下飛到上邊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;
????
轉(zhuǎn)一篇關(guān)于錨點(diǎn)的?http://blog.csdn.net/cjopengler/article/details/7045638
????基本的都有了,下面再看一個動畫效果,點(diǎn)擊new game當(dāng)前,會有一個效果,看看這個效果怎么做的
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);????
關(guān)于cocos2d-x的動畫,簡單點(diǎn)的可以看http://blog.csdn.net/odustggg/article/details/8187843
????
????這樣背景 菜單 點(diǎn)擊newGame以后的動畫效果都就有了,后面就是該做游戲的重頭戲了
????
????
????
????
????
文章結(jié)束給大家分享下程序員的一些笑話語錄: 面試官:熟悉哪種語言
應(yīng)聘者:JAVA
面試官:知道什么叫類么
應(yīng)聘者:我這人實(shí)在,工作努力,不知道什么叫累
面試官:知道什么是包?
應(yīng)聘者:我這人實(shí)在 平常不帶包 也不用公司準(zhǔn)備了
面試官:知道什么是接口嗎?
應(yīng)聘者:我這個人工作認(rèn)真。從來不找借口偷懶
面試官:知道什么是繼承么
應(yīng)聘者:我是孤兒沒什么可以繼承的
面試官:知道什么叫對象么?
應(yīng)聘者:知道,不過我工作努力,上進(jìn)心強(qiáng),暫時還沒有打算找對象。
面試官:知道多態(tài)么?
應(yīng)聘者:知道,我很保守的。我認(rèn)為讓心愛的女人為了自已一時的快樂去墮胎是不道德的行為!請問這和C#有什么關(guān)系??
--------------------------------- 原創(chuàng)文章 By
版本和效果
---------------------------------
總結(jié)
以上是生活随笔為你收集整理的版本效果MoonWarrior cocos2d-x版本 --1的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我的C#文章模块代码
- 下一篇: Response.Write详细介绍