0

C++でシームレスな2Dタイルマップレンダラーを作成しようとしています。目標は、プレイヤーが各マップから別のマップに進むときに、ロード画面をほとんどまたはまったく持たないことです。

例: 各正方形はゾーン/タイルマップです。 赤い四角は表示可能な領域です 上の写真の各正方形はゾーン/タイルマップです。赤い四角は視認可能なカメラです。この例では、各ゾーンは256x256であり、内部に格納されていstd::vector<std::vector<int> >ます。また、カメラの表示可能領域が60x60(32x32タイル)であるとします。

私の現在の問題は、どのように決定するかです。

  1. 指定された各ゾーンから表示するタイル。
  2. 上記のタイルを描画するためのオフセットを計算する方法。

少し関係がありますが、誰かがこのテクノロジーの作成に興味を持っているなら、私はそれに対して喜んでお金を払うつもりです:)

私は貿易によるソフトウェアエンジニアですが、グラフィックスは私の強みではありません。最終的な目標は、シェーダーをサポートするOpenGL3.2を使用して古い学校のRPGを開発することです。

みんな、ありがとう!

4

1 に答える 1

1

うわー、これは私を元に戻します..わかりました、これが私がその日にそれを実装した方法です(directdraw 7を使用していますが、実際にはこの背後にあるグラフィックエンジンは無関係です)。このコードは、カメラが任意の時点で見ることができるものだけを描画します(これは実際に描画する必要がある唯一のものです)。また、このコードは古く、私が最初に開発方法を学び始めた頃のものであることを忘れないでください。あまりきれいではありません:

// set original render location to x = 0, y = 0, width = tileWidth, height = tileHeight
// this is the top left corner of the screen
RECT renderLoc = { 0, 0, g_MapData.m_TileSize, g_MapData.m_TileSize }; 

// the first column of visible tiles is given by the x coordinate divided 
// by the tilesize and first visible row is given by the y coordinate/tileWidth
int xStartCol = g_MapData.m_xCamera / g_MapData.m_TileSize;
int yStartRow = g_MapData.m_yCamera / g_MapData.m_TileSize;

// calculate the number of tiles in the current resolution that are visible
int xVisibleTiles = (dd7.m_ScreenWidth/g_MapData.m_TileSize);
int yVisibleTiles = (dd7.m_ScreenHeight/g_MapData.m_TileSize);

// if the tilesize is not divisible by the screensize then the 
// number of visible tiles will not calculate correctly. It will 
// be a float and since this is truncated, it will contain a row or 
// column less than what it requires. This code compensates for that
// by just adding one more row to round up instead of down.
if (dd7.m_ScreenWidth%g_MapData.m_TileSize) { xVisibleTiles++; }

if (dd7.m_ScreenHeight%g_MapData.m_TileSize) { yVisibleTiles++; }

// now just add the size in tiles of the visible screen to get the end
int xEndCol = xStartCol + xVisibleTiles;
int yEndRow = yStartRow + yVisibleTiles;

// Visible tiles referring to the tiles that can be displayed across and 
//down on the screen (this depends on the resolution set)

// now check if the camera coordinates are divisible by the tile size
int x, y, l; // variables for loops and checks

x = g_MapData.m_xCamera % g_MapData.m_TileSize;
y = g_MapData.m_yCamera % g_MapData.m_TileSize;

if (!x)
{
    // remove a column to draw since it divided perfectly. We originally    
    //added one to the visible rows and columns
xEndCol--;
}
else 
{
// need to move renderLoc RECT. Since there could be half a column    
//exposed which forces us to draw that portion. we only want to draw what 
//is currently on the viewable screen to save memory.
renderLoc.left -= x;
renderLoc.right -= x;
}

// now do the same for rows
if (!y)
{
yEndRow--;
else 
{
renderLoc.top -= y;
renderLoc.bottom -= y;
}

// now check to make sure we're not exceeding map size
if (xEndCol > g_MapData.m_xMaxTiles) { xEndCol = g_MapData.m_xMaxTiles; }
if (yEndRow > g_MapData.m_yMaxTiles) { yEndRow = g_MapData.m_yMaxTiles; }

// Now Draw!
// for each layer 
for ( l = 0; l < g_MapData.m_Layers; l++) {
// draw the rows
for ( x = xStartCol; x <= xEndCol; x++) {
    // column by column
    for ( y = yStartRow; y <= yEndRow; y++) {               
    tileToRender = g_MapData.m_Tiles[x][y][l]; 
// Finish your drawing..
于 2013-03-26T04:10:18.767 に答える