這篇文章幫助我,當我面臨同樣的問題:
XNA 2D Camera
在小地圖上的一部分: 你會需要想爲你的小一的設計風格。一種方法是根據「真實」遊戲世界中的牆壁位置和NPC的點來繪製牆壁矩形。有很多關於如何在互聯網上做這些事情的例子,儘管如果你不想自己搞砸這些事情的話。
例
假設你有一個基於網格的自上而下的遊戲。
您的玩家看到30x30塊,而世界是300x300塊。您可以使用120x120矩形大小(以像素爲單位)繪製例如60x60塊到屏幕的角落作爲小地圖,因此每個塊可以繪製爲4像素。
現在你只需要知道你的播放器兩側有哪30個模塊。如果你知道玩家目前的阻擋程度。你可以做(在一個基於網格的遊戲中):
// We assume that we created a World class that can get a block based on
// a Vector2D.
var playerBlock = World.GetBlockByPosition(player.Position);
// Set the TopLeft position of the minimap accordingly.
Vector2 minimapTopLeft = new Vector(500, 100);
// Draw each 4 pixel block from that TopLeft position (of minimap).
for (int i = -30; i <= 30; i++)
{
for (int j = -30; j <= 30; j++)
{
// Make sure World.GetBlock doesn't return null.
// Offset the location with the player's location (playerBlock).
int blockType = World.GetBlock(playerBlock.X + i, playerBlock.Y + j).Type;
// Draw the 4 pixel blocks based on the i and j vars and the
// minimapTopLeft as offset.
switch (blockType)
{
case 1:
// Draw dirt.
break;
case 2:
// Etc.
break;
default:
// Draw default black block.
break;
}
}
}
我希望這會給你一個關於如何做到這一點的想法。我建議在網上搜索更多的例子。
我喜歡你的想法,但不幸的是我不知道如何在我的遊戲中實現網格。你知道任何有用的教程嗎? – user2904986
不知道最好的一個。但是搜索「XNA 2D基於tile的教程」。它基本上涉及保持包含您的關卡/世界的二維數組。 – Measuring