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 an开发者_开发百科d getting all of these out, or even figuring out where these islands are turns complex rather quickly.
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.
精彩评论