Android cocos2d 彈弓遊戲 Catapult 原始碼

來源:互聯網
上載者:User

根據下面兩篇文章, 我一步步實踐, 成功讓程式在 Samsung Galaxy G2 上運行起來, 感謝這些貢獻者

http://www.raywenderlich.com/4756/how-to-make-a-catapult-shooting-game-with-cocos2d-and-box2d-part-1

http://mssyy2010.blog.51cto.com/4595971/847000

至於程式的設計和邏輯, 上面兩篇文章介紹得很清楚了

現在把原始碼提供給大家, 可以從下面的 link 下載

https://github.com/PaynePan/share_src/archive/master.zip

使用方法

1)  解壓到cocos 目錄下一級, 比如:  d: \cocos2d-2.1rc0-x-2.1.2\catapult\

        catapult 下有目錄  Classes 和 proj.android

2)  import  proj.android 到 eclipse 中

3)  在 cgywin 中 運行 proj.android/build_native.sh, 產生 libgame.so 

4)  再在 eclipse 下編譯運行

說明

有幾個注意點,說明一下

項目直接使用已經啟動並執行 HelloWorld 改寫過來,  主要就是改寫  HelloWorldScene.cpp, HelloWorldScene.h

 

1)  build_native.sh 資源檔的 copy 部分略去

coco2dx Android 最頭痛的就是 cygwin中運行 build_native.sh 複製資源檔,  那些操作和 win7 下的許可權不相容

所以去掉了 copy 部分, 反正這些檔案已經在 proj.android/asset中了

2) 由於 cocos2d 也在不斷改進, 現在代碼與原文有兩處不同

原文

 

    CCDelayTime *delayAction = CCDelayTime::actionWithDuration(0.2f);        CCCallFunc *callSelectorAction = CCCallFunc::actionWithTarget(this, callfunc_selector(HelloWorld::resetGame));        this->runAction(CCSequence::actions(delayAction,                                            callSelectorAction,                                            NULL));     

現在
    scheduleOnce(schedule_selector(HelloWorld::resetGame),0.2f);     

原文

 

 

    CCTouch *touch = (CCTouch *)touches->anyObject();     CCPoint location = touch->locationInView(touch->view());     location = CCDirector::sharedDirector()->convertToGL(location); 

 

 

改為

 

CCTouch* touch = (CCTouch*)( touches->anyObject() );CCPoint location = touch->getLocation();

 

3) 在tick中 增加了再次裝彈的邏輯

 

if (m_bulletBody && m_bulletJoint == NULL) { b2Vec2 position = m_bulletBody->GetPosition(); CCPoint myPosition = this->getPosition(); CCSize screenSize = CCDirector::sharedDirector()->getWinSize(); static int count = 0;if ( ++count % 60 ==0) {CCLog("++++++++after  x:%f, y:%f", position.x, position.y);if ( abs(m_bullet_position.x-position.x) < 1.5f &&abs(m_bullet_position.y-position.y) < 1.5f ) {attachBullet();return;}m_bullet_position = position;}// Move the camera. if (position.x > screenSize.width / 2.0f / PTM_RATIO) { myPosition.x = -MIN(screenSize.width * 2.0f - screenSize.width, position.x * PTM_RATIO - screenSize.width / 2.0f); this->setPosition(myPosition); } } 

 

 

現在可以簡單地玩遊戲了.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.