位置: 编程技术 - 正文

基于像素的碰撞检测(移植到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)

  • 筹建期间发生的开办费计入什么科目
  • 招聘只招一个人
  • 去税务局作废申报需要带哪些证件
  • 付款后发票可以抵扣吗
  • 应收账款包含应付款吗
  • 税控盘抵扣增值税有时间限制吗
  • 增值税普通电子发票可以抵税吗
  • 企业用银行存款购买原材料
  • 履约保证金需纳什么税
  • 开具增值税发票的注意事项有哪些?
  • 供应商赠送
  • 自然人是否适用财政部税务总局2022年第15号公告
  • linux中压缩
  • 月末汇兑损益怎么算
  • 房产的评估增值属于土地增值税征税范围对吗
  • 应付票据贴现息计入
  • 如何调整任务栏图标大小
  • 华为mate50 pro
  • 医保养老保险怎么查
  • 企业收到政府出资款交增值税
  • 购车人丢失发票怎么查
  • php和ajax
  • 取得交易性金融资产的交易费用
  • 销售汇总怎么做分录
  • vue自定义日历组件
  • tcpdump 监听指定端口
  • linux的nfs如何使用
  • 软件的摊销期限
  • 开发票零税率和免税是一样的意思吗
  • 企业所得税月月交吗
  • 永久性差异会计不确认收入
  • 浅谈建筑地基基础加固施工技术亲
  • 员工加班打车费报销
  • 变更股东投资比例
  • 土地使用发票
  • mysql 执行过程
  • sqlserver数据库事物日志已满
  • 待处理流动资产损失属于什么科目
  • 费用多报销了,但已经给了,怎么办
  • 没有收入如何做账
  • 什么叫同级财政收支
  • 其他应付款如何平账
  • 管理费用结转到哪个科目
  • 预提工资如何算增值税
  • 手工账月末结账步骤
  • 赠送货物金额为多少
  • 取暖费用摊销吗
  • 留存收益和未分配利润一样吗
  • mysqlsh
  • 怎么提高sql语句
  • winXP系统还能用吗
  • centos virbr0
  • fedora soas
  • win7旗舰版关闭强制签名
  • centos怎么查看文件
  • 在win7操作系统中通过什么可以查看计算机的配置
  • 苹果15手机价格和图片颜色
  • Mac怎么去掉开机密码
  • centos分区命令
  • 4G内存时linux的mtrr表不正确的解决
  • xp如何升级到sp3
  • win10无u盘装系统教程
  • ie11打不开闪退解决办法win 7
  • window10打补丁
  • win7清洗打印机喷头步骤
  • win7怎么安装网络驱动程序
  • xtemplate node.js 的使用方法实例解析
  • ubuntu 20.4安装
  • css应用领域
  • unity2d ui
  • 基于python的系统
  • android应用开发基础课后答案
  • python里的lambda怎么用
  • 发票一年可以开多少
  • 咸阳国税局长是哪里人
  • 电子税务局电子送达文书怎么签收
  • 建筑业小规模纳税人工程结算增值税
  • 税盘注销了怎么申报增值税
  • 广东省外经贸厅官网
  • 国家税务总局中山市税务局港口税务分局
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设