2013-02-08 1 views
0

의 당신이 한 가정 해 봅시다 : spriteBatch.Draw(myTexture, myRectangle, Color.White);XNA에서 스프라이트의 사각형 너비와 텍스처 너비의 차이점은 무엇입니까?

을 그리고 당신이 있습니다

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

좋아, 우리는 (30)의 사각형의 폭 그래서 지금의이 myTexture의 폭이 그래서 100

입니다 가정 해 봅시다 첫 번째 줄에서는 스프라이트의 너비가 30이됩니까 myTexture 너비가 100 인 채로 사각형 너비로 설정했기 때문입니다. 또는 스프라이트의 너비가 텍스처의 너비이기 때문에 100이됩니까?

+0

그냥 사용해보세요! ^^ 3D 프레임 워크에 의문이 생길 때 모든 가능성을 한 번에 시도해보십시오 (예 : texture> rectangle, texture Mualig

+0

나는 시도했지만 심각하게 혼란 스럽다. 내가 정말로 알아야 할 것은 사각형이 실제로 무엇을하는지, 텍스처가 스프라이트에 어떤 영향을 미치는지입니다. – CsharpFrustration

+1

귀하의 질문에 이미 답변되었습니다 : http://stackoverflow.com/questions/5189833/what-is-source-rectangle-in-spritebatch-draw-in-xna – Mualig

답변

0

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(); 

나는 사각형이 인출 방법에 사용되는 순서를 혼합 수 있습니다.

편집; 소스 사각형 만 사용하면 화면 위치에 텍스처 조각 만 그릴 수 있으며 대상 만 사용하면 텍스처를 원하는 위치에 맞게 크기를 조정할 수 있습니다.