1

繰り返されるタイル(地形、壁、水など)がたくさんある(潜在的に大きい)横スクロールの2Dワールドがあります。たとえば、非常に高くなる可能性がある大きな「丘」がありますが、同じ小さなものを使用してレンダリングされます。 「ロック」テクスチャの一部。

この世界のストレージとレンダリングを最適化したいと思います(1つの大きなクワッドを描画し、同じ繰り返しテクスチャを適用する方が、多数の小さな隣接するクワッドを個別に描画するよりも優れています)。

それを行うための良い方法は何ですか?現在、2つの解決策が考えられます。

  1. マップデザイナーが「チャンク」(繰り返されるタイルの大きな長方形)を手動で指定できるようにします
  2. マップ設計者がタイルごとにマップを設計し、チャンクを自動的に計算できるようにします(これを行うための適切なアルゴリズムは何ですか?)

あなたが同様のゲームに取り組んだことがあるなら、あなたの特定の解決策を聞いてみたいです。

4

2 に答える 2

0

Since you won't draw rectangles anyway (but triangles), I suggest to choose the second option. Furthermore, never trust the user of your program.

The first task is to divide the map into polygons of the same texture. Because your terrain is based on a grid, this can be achieved very easily by a kind of flood fill in combination with a marker algorithm, which runs e.g. like this:

- n := 0 // will be the polygon numbers
- Iterate over each grid cell
    - If cell is marked, continue with next cell
    - mark cell with n
    - check adjacent cells for the same texture and mark them accordingly * 
    - n := n + 1

* This step can be performed in various ways: FloodFill. Furthermore, you should store an edge cell for each chunk. I.e. a cell that has at least one adjacent cell with a different texture. Let's call this the seed cell.

Then you have your grid marked with the polygon numbers and n is equal to the polygon count.

The next step is to extract the polygons. This is, where the seed cell will be of help. For each chunk, start at the seed cell and run along the edges of the chunk collecting all corner points. These corner points will make your polygon.

After that you have a set of polygons. The final step is to triangulate the polygon for rendering. This can be achieved e.g. with the Ear Cutting / Clipping Algorithm or others.

于 2012-07-05T18:43:40.840 に答える