는 내가 원하는 것은, 안에 다른 사각형을 고정하는 방법입니다 내가클램프 사각형 안에 큰 사각형
X = 0, Y = 0, Width = 25, Height = 25.
와 함께 XNA 사각형이 있다고 가정하자 있도록 작은 사각형 결코 '잎'더 큰 하나의 경계 . 내가 가진 새로운 사각형을 만들 경우, 예를 들어
: 내가 가진 새로운 사각형을 만들 경우,
X = 23, Y = 20, Width = 2, Height = 5.
또한 :
X = 23, Y = 20, Width = 10, Height = 10,
내가 가진 사각형을 반환하는 방법을 원하는
X = -8, Y = 8, Width = 10, = 10,
다음과 함께 사각형을 반환하는 메서드를 원합니다.
한편X = 0, Y = 8, Width = 2, Height = 10.
내가 일할 수있는 클램핑을 얻었다. 여전히, 그 추악한 코드의 대량, 그래서 새로운 질문은, 어떻게 이것을 단순화 할 수 있습니까?
if (SelectionRectangle.X < 0)
{
SelectionRectangle.Width = SelectionRectangle.Width + SelectionRectangle.X;
SelectionRectangle.X = 0;
}
if (SelectionRectangle.X + SelectionRectangle.Width > tileset.Width)
{
if (SelectionRectangle.X > tileset.Width)
{
SelectionRectangle.X = tileset.Width;
SelectionRectangle.Width = 0;
}
else
{
SelectionRectangle.Width = tileset.Width - SelectionRectangle.X;
}
}
if (SelectionRectangle.Y < 0)
{
SelectionRectangle.Height = SelectionRectangle.Height + SelectionRectangle.Y;
SelectionRectangle.Y = 0;
}
if (SelectionRectangle.Y + SelectionRectangle.Height > tileset.Height)
{
if (SelectionRectangle.Y > tileset.Height)
{
SelectionRectangle.Y = tileset.Height;
SelectionRectangle.Height = 0;
}
else
{
SelectionRectangle.Height = tileset.Height - SelectionRectangle.Y;
}
}
시도한 것을 보여줄 수 있습니까? 당신이 작성한 코드는 왜 작동하지 않았고, 당신의 문제는 무엇입니까? – TJHeuvel
클램프를 적용 할 곳을 알려주십시오. –