位置: 编程技术 - 正文

基于像素的碰撞检测(移植到cocos2dx 3.x)(基于像素的分类方法)

编辑:rootadmin
感谢原文: 2.x的,我修改了一下,这个版本是Cocos2d-x 3.x可用版本。Pixel Perfect Collision Detection (Using Cocos2d-x 3.x)This post found its way because I couldnt find the answer to one of the questions I asked on StackOverflow ( and thought there would be others like me in search for an answer.Collision detection is an integral part of almost all games. It is used to find when a bullet hits an enemy or when you bump into a wall etc.There are many different requirements when we do collision detection and depending on our game we choose one of the many detection techniques.The default Collision detection mechanism used by games and provided in almost all game engines and frameworks is a “Bounding Box” collision.Simply put, a “Bounding Box” collision detection system the sprites/objects being checked for collision are treated as the smallest rectangle which completely engulfs them. Then these two Boxes are checked if they are colliding with each other.But sometimes this very simple collision detection system is not accurate. Specially when we use sprites with alpha values (mostly png files) or when our objects are rotated by some angles. See the image below: Pixel – Perfect collision detection is a system where we check if the objects concerned are actually colliding rather than just being part of a bounding box which is bigger than their size. WARNING: This system though more accurate is obviously more performance intensive and hence depending on your game requirements choose wisely about which of the different systems you want to use.TIP: This system though written specially for Cocos2d-x framework can be easily understood and implemented for any language/framework you are using.So its time to get our hands dirty,We are going to develop a Singleton Class for collision detection and just plug and play this in any project we are doing.Things used:1. Singleton Class – CollisionDetection2. Opengl Vertex and Fragment Shaders3. CCRenderTexture Class – Cocos2d-xTheory:1. Create a CCRenderTexture which is going to serve as a secondary draw buffer.2. We first do a simple collision detection (Bounding Box) to check if the two sprite’s bounds are colliding3. If step 2 is a success then we are going to draw the two concerned objects in our secondary buffer we created in step 1. (We are going to set its visibility to false, so that even though we draw something, nothing will we visible to the end user)4. Using openGL fragment shaders we are going to draw one of the objects completely RED and the other completely BLUE! 5. Using another of openGL functionality glReadPixels we are going to read the pixels data of all the pixels in the Rectangular area (Intersection area) of the bounding box collision6. We are then going to loop through all the pixel values and check if a single pixel has BOTH the RED and the BLUE pixels. If they have then the objects are actually colliding or else not.Now here is the code for the above steps. I have commented the code for you to understand what is going on. If there are any questions please leave in the comments and I will try and answer to the best of my knowledge

推荐整理分享基于像素的碰撞检测(移植到cocos2dx 3.x)(基于像素的分类方法),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:基于像素的图像增强方法是一种非线性灰度变换,像素碰撞检测,像素碰撞检测,基于像素的分类方法,基于像素的图像,也可以称为,像素碰撞检测,基于像素的图像,也可以称为,像素碰撞3d,内容如对您有帮助,希望把文章链接给更多的朋友!

CollisionDetection.h

CollisionDetection.cpp

SolidColorShader.fsh基于像素的碰撞检测(移植到cocos2dx 3.x)(基于像素的分类方法)

SolidVertexShader.vsh

For using the Collision Detection Class:

1. Initialize the CCRenderTexture object

2. Call the Singleton function whenever collision detection required

cocos2dx 3.2 读写XML,基于tinyxml2封装的易使用,更灵活的XML接口。中文国际化。 简介cocos2dx3.2读写XML使用的是tinyxml2库。tinyxml2是一个轻量的解析XML的开源库,C编写,跨平台,内存占用很小。解析文件时,在内存中生成DOM模型,即文

cocos2dx onpause崩 原文:

cocos2dx3.2 xcode中资源路径设置问题 在xcode中,将资源分类,然后将各自的文件夹添加到Resources,运行程序的时候老是报错,说是找不懂资源,原因就是找不到资源路径。那么如何设置呢?1

标签: 基于像素的分类方法

本文链接地址:https://www.jiuchutong.com/biancheng/372619.html 转载请保留说明!

上一篇:Cocos2dx 3.0 实战之—— 重写《超级马里奥》其八 主菜单界面(cocos2d教程)

下一篇:cocos2dx 3.2 读写XML,基于tinyxml2封装的易使用,更灵活的XML接口。中文国际化。(cocos creator读取json)

  • 小规模纳税人印花税怎样计算
  • 个人所得税劳务报酬范围
  • 跨年增票能开红冲吗?
  • 公司申报个税流程
  • 家具厂投入多少钱
  • 房地产涉及的税种和税率
  • 工商银行特色贷款
  • 发票上是17%的税率吗
  • 收到销售退回时应当冲减
  • 怎么把原材料转为成本
  • 企业向个人借款需要交印花税吗
  • 银行给企业的存款怎么存
  • 计提所得税是在结转12月损益之前还是之后
  • 税款流失是什么意思
  • 土地的增值税进项能否抵扣
  • 商业承兑汇票申请流程
  • 进项发票已经抵扣怎么做退回处理
  • 资金印花税
  • 建筑中小企业
  • 收到带息商业票据贴现会计处理
  • 企业所得税法的规定可在税前扣除的
  • 苹果电脑开机声音怎么关
  • 电脑医生怎么卸载
  • 售后回购不符合法律规定
  • 场外期权会计核算
  • 都有哪些收据可以抵税
  • 加工费计入
  • 电子缴款凭证能代替完税证明吗
  • 银行贷款用途能改吗
  • 民间非营利组织会计制度
  • 开公司车出差违章了谁负责
  • 民间非盈利组织会计要素组成
  • 如何修改php网页内容
  • 发票冲红如何进入系统
  • 销售费用包括哪些明细科目
  • 支付宝支付凭证在哪里查
  • 债权投资产生的暂时性差异确认所得税吗
  • 零申报年报需要哪些表格
  • 处理固定资产如何做账
  • 土地摊销计入成本还是费用
  • 机动车统一发票怎么开
  • 工业企业制造费用具体怎么摊
  • 京东提现到公账怎么取消
  • 金税盘分盘可以全额抵扣吗
  • 企业网银年服务费怎么做账
  • 外购商品用于促销能抵扣吗
  • 进项税转出税额
  • 哪些合同不受法律保护
  • 本期缴纳上期应纳税额怎么算
  • sqlserver登录日志
  • sqlserver怎么用sql创建表
  • win7断电后无法启动
  • 神州战神bios怎么进
  • windoes版本
  • win7如何查看电脑
  • linux动态库的制作
  • nfs安装配置
  • ebr.ahrcu
  • win7系统怎么开wifi热点
  • win7禁用驱动签名后可以正常启动吗
  • 升级win10怎么激活
  • 五种修改方法
  • win7安装软件后所有打开变成记事本
  • linux引导程序有哪些
  • win8 设置
  • win8系统崩溃无法开机
  • Linux如何使用命令
  • ExtJS扩展 垂直tabLayout实现代码
  • 常用adb命令大全
  • linux shell打开文件
  • cocos2d教程
  • 提取字符串的公式
  • nodejs使用es6
  • 绑定安卓
  • 彩票税率税率
  • 深圳市财政上交广东省吗
  • 河南新农合缴费记录可以在哪里查?
  • 全国税务系统全面从严治党工作会议2023年
  • 延期申报预缴税款滞纳金问题
  • 耕地占用税是土地增值税扣除项目吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设