1

私は現在、本「XNA 4.0 Game Development by Example」で、Gemstone Hunter を使用した TileMaping について学んでいます。299 ページで何をしているのかを説明していますが、今度は各メソッドが何をしているのかを示しています。いくつか質問がありますが、主な質問は、get と return は何をするのですか?:

誰にも解決を求めているわけではありませんが、get は何をしているのですか?

また、タイルシートが何をしているのか知りたいです。

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
4

1 に答える 1

2

主な質問に答えるには

#region Tile and Tile Sheet Handling
public static int TilesPerRow
{
    get { return tileSheet.Width / TileWidth; }
}

これは読み取り専用のプロパティです。呼び出してアクセスしようとするとYourClass.TilesPerRow、ブロック内のコードが実行され、その値が返されます。

アクセサgetと呼ばれます。MSDN で説明されている set アクセサーもあります

get アクセサーのコード ブロックは、プロパティが読み取られるときに実行されます。プロパティに新しい値が割り当てられると、 set アクセサーのコード ブロックが実行されます。アクセサーが設定されていないプロパティは、読み取り専用と見なされます。get アクセサーのないプロパティは、書き込み専用と見なされます。両方のアクセサーを持つプロパティは読み書き可能です。

プロパティには値がないため、setこのプロパティに値を割り当てて読み取り専用にすることはできません。

プロパティの MSDN ガイドは次のとおりです。

http://msdn.microsoft.com/en-us/library/vstudio/w86s7x04.aspx

あなたの場合、シートの全幅をタイルの幅で割っています。これは、(名前が示すように) 1 行に配置できるタイルの総数につながります。

于 2013-11-08T15:27:56.813 に答える