cocos2dx游戏开发简单入门视频教程 (cocos2d-x)- 第3天

第1天的地址:

http://blog.csdn.net/xingxiliang/article/details/18557631

书接上回:今天我们让我们的飞镖可以打死怪物。

更新:出品了box2d编辑工具PhysicsEditor的视频(一起做一个实战级别的游戏,需要MAC操作系统)http://blog.csdn.net/s_xing/article/details/21331459

更新:出品了box2d物理引擎视频http://blog.csdn.net/s_xing/article/details/20836727

更新:终于出进阶篇了http://blog.csdn.net/s_xing/article/details/20165097请大家关注


avi版本可以方便的在手机,pc上查看。下载地址:http://pan.baidu.com/s/1ELk78


1. 数据结构的选择

// array 插入 删除效率低 ;查找、遍历效率高 
// list     插入 删除效率高;查找、遍历效率 低
// 添删:怪物出现 飞镖出现  碰撞 用的次数少
// 遍历: 1.0/fps 时间进行一次遍历        用的次数多
// 选用array

2. 碰撞检测的函数

void HelloWorld::update(float delta) // delta = 1.0 / fps
{
	CCArray* targetToDelete = new CCArray;
	CCArray* projToDelete = new CCArray;
	CCObject* itarget;
	CCObject* iproj;
	CCARRAY_FOREACH(_targets, itarget){
		CCSprite* target = (CCSprite*)itarget;

		CCRect targetZone = CCRectMake(target->getPositionX(),
			target->getPositionY(),
			target->getContentSize().width,
			target->getContentSize().height);

		CCARRAY_FOREACH(_projs, iproj){
			CCSprite* proj = (CCSprite*)iproj;
			CCRect projZone = CCRectMake(proj->getPositionX(),
				proj->getPositionY(),
				proj->getContentSize().width,
				proj->getContentSize().height);

			if (projZone.intersectsRect(targetZone)){
				projToDelete->addObject(iproj);
				targetToDelete->addObject(itarget);
			}
		} // end of iterate projectile


	} // end of iterate target

	CCARRAY_FOREACH(projToDelete, iproj){
		_projs->removeObject(iproj);
		CCSprite* proj = (CCSprite*)iproj;
		proj->removeFromParentAndCleanup(true);
	}

	CCARRAY_FOREACH(targetToDelete, itarget){
		_targets->removeObject(itarget);
		CCSprite* target = (CCSprite*)itarget;
		target->removeFromParentAndCleanup(true);
	}

	targetToDelete->release();
	projToDelete->release();}

注意:不可以在遍历CCArray的同时 从CCArray中删除成员。


3. 使用CCSprite->setTag(int) 

这样可以为每一种不同的精灵打上标志,区分不同精灵。



上传到了优酷

http://v.youku.com/v_show/id_XNjY0MjEzNzI0.html       第1课

http://v.youku.com/v_show/id_XNjY0MjMzMzYw.html   第2课

http://v.youku.com/v_show/id_XNjY0MjU1OTcy.html    第3课

http://v.youku.com/v_show/id_XNjY0MzQxMDE2.html  第4课

http://v.youku.com/v_show/id_XNjY1MTI3NjYw.html     第5课

http://v.youku.com/v_show/id_XNjY1MTI5ODQw.html    第6课



高清还请从百度网盘下载。


转载请注明出处:http://blog.csdn.net/xingxiliang/article/details/18557631

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 19
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 19
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值