0

あなたがこれをしたとしましょう:spriteBatch.Draw(myTexture, myRectangle, Color.White);

そして、あなたはこれを持っています:

myTexture = Content.Load<Texture2D>("myCharacterTransparent");
myRectangle = new Rectangle(10, 100, 30, 50);

これで、長方形の幅が 30 になりました。myTexture の幅が 100 だとしましょう。

myTexture最初の行では、幅が 100のままで、長方形に設定した幅なので、スプライトの幅を 30 にしますか? それともテクスチャの幅なので、スプライトの幅は 100 になりますか?

4

1 に答える 1

0

Draw メソッドで使用される Rectangles は、Texture2D のどの部分を rendertarget のどの部分 (通常は画面) に描画するかを定義します。

たとえば、これがタイルセットの使用方法です。

class Tile
{
    int Index;
    Vector2 Position;
}

Texture2D tileset = Content.Load<Texture2D>("sometiles"); //128x128 of 32x32-sized tiles
Rectangle source = new Rectangle(0,0,32,32); //We set the dimensions here.
Rectangle destination = new Rectangle(0,0,32,32); //We set the dimensions here.
List<Tile> myLevel = LoadLevel("level1");

//the tileset is 4x4 tiles

in Draw:
spriteBatch.Begin();
foreach (var tile in myLevel)
{
    source.Y = (int)((tile.Index / 4) * 32);
    source.X = (tile.Index - source.Y) * 32;

    destination.X = (int)tile.Position.X;
    destination.Y = (int)tile.Position.Y;

    spriteBatch.Draw(tileset, source, destination, Color.White);
}
spriteBatch.End();

仕事中に頭の上からこれを行っているため、draw-methodで使用される長方形の順序を混同した可能性があります。

編集; Source Rectangle のみを使用すると、画面の位置にテクスチャの一部のみを描画できます。一方、Destination のみを使用すると、テクスチャを任意の場所に合わせてスケーリングできます。

于 2013-02-08T14:59:24.953 に答える