Android cocos2d 弹弓游戏 Catapult 源代码
2013-04-26 19:36
197 查看
根据下面两篇文章, 我一步步实践, 成功让程序在 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
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 也在不断改进, 现在代码与原文有两处不同
原文
现在
scheduleOnce(schedule_selector(HelloWorld::resetGame),0.2f);
原文
改为
3) 在tick中 增加了再次装弹的逻辑
现在可以简单地玩游戏了.
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); } }
现在可以简单地玩游戏了.
相关文章推荐
- Android cocos2d 弹弓游戏 Catapult 源代码
- Android cocos2d 弹弓游戏 Catapult 源代码 完成
- 【iOS-cocos2d-X 游戏开发之十五】Cocos2dx中响应Android的Back(返回)与Menu(小房子)事件&&Cocos2dx自动释放粒子内存函数!
- cocos2d-x android黑屏后返回游戏卡顿
- cocos2d-x(quick--cocos2d-x)引擎开发的游戏在android平台上,锁屏,按HOME键,重反游戏后黑屏问题
- Cocos2d-x游戏中默认的AndroidManifest.xml的解析
- iOS和android游戏纹理优化和内存优化(cocos2d-x)
- Cocos2d-x 结合Box2D开发Android游戏配置方法
- 11个cocos2d-x2.2.3经典游戏源代码
- [cocos2d-x·解Bug]关于cocos2d-x游戏在android锁屏状态下播放Bgm的解决方法
- 【Cocos2d-x 3.0】游戏开发之android交叉编译
- iOS和android游戏纹理优化和内存优化(cocos2d-x)
- 用cocos2d-android开发android游戏时调用box2d中的native本地函数问题
- Android开源项目:捕鱼达人游戏源代码
- Android游戏开发之Cocos2d-android-1 安装运行 (一)
- cocos2d-x android黑屏后返回游戏卡顿
- cocos2d-android游戏引擎介绍、下载
- 向大家推荐个android的游戏引擎——cocos2d-x
- cocos2d-html5 游戏实战源代码大集合和下载(包括flappy,popstar等----持续更新中----)
- Cocos2d-x游戏开发之代码如何识别ios平台与android并分开处理