我现在正在“XNA 4.0 Game Development by Example”一书中使用 Gemstone Hunter 学习 TileMaping。在第 299 页上,它讲述了它正在做什么,但现在每个方法正在做什么。我有一些问题,但主要的是,get & return 有什么作用?:
我不是要求任何人来解决它,而是在做什么?
我也想知道 tileSheet 在做什么。
我想了解 MapWidth 和 MapHeight。
(我正在尝试写评论以了解每件作品的作用)
#region Declarations
//TileWidth, and TileHeight are the size that each tile will be when playing and editing the game.
public const int TileWidth = 48;
public const int TileHeight = 48;
//MapWidth and MapHeight do... I don't know.
public const int MapWidth = 160;
public const int MapHeight = 12;
//MapLyaers represent the three back grounds in the MapSquare class.
public const int MapLayers = 3;
//skyTile is the blue tile that will be on the background, or the
private const int skyTile = 2;
//MapSquare organizes the tile sheet into map cells by width and height.
static private MapSquare[,] mapCells =
new MapSquare[MapWidth, MapHeight];
//Tells the the game if its playing or editing the maps.
public static bool EditorMode = true;
public static SpriteFont spriteFont;
static private Texture2D tileSheet;
#endregion
#region Initialization
//The Initialize() method establishes all of the MapCells as MapSquares with empty tiles on each layer.
//On back ground skyTile (2) will be the blue background, 0 will be transparent.
static public void Initialize(Texture2D tileTexture)
{
tileSheet = tileTexture;
for (int x = 0; x < MapWidth; x++)
{
for (int y = 0; y < MapHeight; y++)
{
for (int z = 0; z < MapLayers; z++)
{
mapCells[x, y] = new MapSquare(skyTile, 0, 0, "", true);
}
}
}
}
#endregion
#region Tile and Tile Sheet Handling
public static int TilesPerRow
{
get { return tileSheet.Width / TileWidth; }
}
public static Rectangle TileSourceRectangle(int tileIndex)
{
return new Rectangle(
(tileIndex % TilesPerRow) * TileWidth,
(tileIndex / TilesPerRow) * TileHeight,
TileWidth,
TileHeight);
}
#endregion