Draw-method에서 사용되는 직사각형은 렌더링 타겟의 어떤 부분 (보통 화면)에 Texture2D의 어떤 부분을 그려야 하는지를 정의합니다.
이것은 우리가 예를 들어 타일 세트를 사용하는 방법입니다. 직장에서하는 동안 내 머리의 상단이를하고있는 중이 야으로
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();
나는 사각형이 인출 방법에 사용되는 순서를 혼합 수 있습니다.
편집; 소스 사각형 만 사용하면 화면 위치에 텍스처 조각 만 그릴 수 있으며 대상 만 사용하면 텍스처를 원하는 위치에 맞게 크기를 조정할 수 있습니다.
그냥 사용해보세요! ^^ 3D 프레임 워크에 의문이 생길 때 모든 가능성을 한 번에 시도해보십시오 (예 : texture> rectangle, texture
Mualig
나는 시도했지만 심각하게 혼란 스럽다. 내가 정말로 알아야 할 것은 사각형이 실제로 무엇을하는지, 텍스처가 스프라이트에 어떤 영향을 미치는지입니다. – CsharpFrustration
귀하의 질문에 이미 답변되었습니다 : http://stackoverflow.com/questions/5189833/what-is-source-rectangle-in-spritebatch-draw-in-xna – Mualig