将纹理的边缘提取到数组中以进行碰撞检测
作为业余时间的消遣,我正处于创建 2D 游戏的早期阶段。
对于这个游戏,我想创建可破坏的地形,并希望我能在这个问题上得到一些好主意。我计划使用 FarseerPhysics 来处理一些通用物理,例如盒子。
我的问题是我不确定应该如何与物理引擎一起创建可破坏的地形。
到目前为止,我最好的想法是在内存中保留一个黑白图像,其中黑色代表某种类型的地面,然后随着游戏过程中事物的变化而绘制和删除该图像。
然后,每次图像发生变化时,都会尝试提取边缘之间具有一定距离的顶点,并使用它们在物理引擎中创建多边形。
不太确定我应该如何执行此操作,因为图像可能有多个多边形小岛并将所有这些都取出来,甚至弄清楚这些岛在哪里很快就会变得复杂。
I'm in the early stages of creating a 2D game as a something to do in my spare time.
For this game I want to create destructible terrain and was hoping I can get some good ideas on the matter. I plan on using Farseer Physics for some general physics such as boxes.
My problem is that I'm not sure how I should create the destructible terrain together with a physics engine.
My best idea so far is to keep a black and white image in memory where black represents some type of ground and then drawing and removing to this image as things change during the course of the game.
Then every time the image changes try to extract the vertexes of the edges with a certain distance between them and using them to create polygons in the physics engine.
Not quite sure how should I do this as the image can have multiple small islands of polygons and getting all of these out, or even figuring out where these islands are turns complex rather quickly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会在下载页面使用旧版本的 Farseer 物理,最新的旧版本是 2.1.3
然后查看此处有关此事的文档:http://www.farseergames.com/storage/farseerphysicals/Manual2.1.htm#_Toc213068512
尝试将地图分割成更小的地图使重新创建的过度程度尽可能小。并且尽量不要编辑地形的单个像素,使用 RenderTarget2D 。
有
Vertices.CreatePolygon()
的重载,它输出一个 List<> 。顶点数组。我做了一些类似的事情,但是使用 3D 地形,但它只有大约 64x64 像素大。
I'd use the older versions of Farseer Physics availbale at the downloadpage, the latest old version is 2.1.3
Then take a look at the documentation located here on the matter: http://www.farseergames.com/storage/farseerphysics/Manual2.1.htm#_Toc213068512
Try splitting the map into smaller pices to keep the re-creation overhed as small as possible. And try not to edit the individual pixels of the terrain, use
RenderTarget2D
.There are overloads of the
Vertices.CreatePolygon()
which outputs a List<> of Vertice arrays.I did something similiar but with 3D terrain, but it was only about 64x64 pixels big.