큰 창에서 저해상도 게임을 만들고 싶습니다. (예 : 960x540 크기의 창에서 96x54 해상도).해상도가 증가하지 않는 XNA 크기 조정 창
어떻게하면됩니까? 선호하는 백 버퍼 너비와 높이와 독립적으로 창 크기를 조정할 수 있습니까? 아니면 내가 그리는 저해상도 렌더링 타겟을 유지해야하며 가장 가까운 텍스처 샘플링을 조정할 때 내 윈도우에 전체 화면 쿼드로 그립니다. 사전에
감사합니다,
xoorath
큰 창에서 저해상도 게임을 만들고 싶습니다. (예 : 960x540 크기의 창에서 96x54 해상도).해상도가 증가하지 않는 XNA 크기 조정 창
어떻게하면됩니까? 선호하는 백 버퍼 너비와 높이와 독립적으로 창 크기를 조정할 수 있습니까? 아니면 내가 그리는 저해상도 렌더링 타겟을 유지해야하며 가장 가까운 텍스처 샘플링을 조정할 때 내 윈도우에 전체 화면 쿼드로 그립니다. 사전에
감사합니다,
xoorath
당신이 (더하기 당신이 사후 처리 쉐이더를 수행하려는 경우 당신을 위해 더 쉬울 것이다) 좋은 생각이 될 수 있습니다에 대해 이야기하고있는 RenderToTexture 방법을 사용. 또는 Window 크기를 설정할 수도 있지만 코드는 바탕 화면에서만 작동합니다.
프로젝트에서 그 2 참조 추가해야합니다
GraphicsDeviceManager.PreferredBackBufferWidth = 96;
GraphicsDeviceManager.PreferredBackBufferHeight = 54;
IntPtr ptr = this.Window.Handle;
Form form = (Form) Control.FromHandle(ptr);
form.Size = new Size(960, 540);
것은 내가 "로 렌더링을 선택하는 경향이
using System.Drawing;
using System.Windows.Forms;
을 그리고 당신의 게임 클래스 (즉, 초기화 방법) 텍스처 "솔루션을 사용하여 왜곡없이 전체 화면과 같은 것을 허용 할 수 있습니다.
내가 이것을 달성하기 위해 사용하는 클래스는 일반적으로 같은 같습니다 업데이트 할 수있는 모든 중요한 전화로
VirtualScreen virtualScreen;
protected override void Initialize()
{
virtualScreen = new VirtualScreen(96, 54, GraphicsDevice);
Window.ClientSizeChanged += new EventHandler<EventArgs>(Window_ClientSizeChanged);
Window.AllowUserResizing = true;
base.Initialize();
}
void Window_ClientSizeChanged(object sender, EventArgs e)
{
virtualScreen.PhysicalResolutionChanged();
}
: 내 게임의 다음
class VirtualScreen
{
public readonly int VirtualWidth;
public readonly int VirtualHeight;
public readonly float VirtualAspectRatio;
private GraphicsDevice graphicsDevice;
private RenderTarget2D screen;
public VirtualScreen(int virtualWidth, int virtualHeight, GraphicsDevice graphicsDevice)
{
VirtualWidth = virtualWidth;
VirtualHeight = virtualHeight;
VirtualAspectRatio = (float)(virtualWidth)/(float)(virtualHeight);
this.graphicsDevice = graphicsDevice;
screen = new RenderTarget2D(graphicsDevice, virtualWidth, virtualHeight, false, graphicsDevice.PresentationParameters.BackBufferFormat, graphicsDevice.PresentationParameters.DepthStencilFormat, graphicsDevice.PresentationParameters.MultiSampleCount, RenderTargetUsage.DiscardContents);
}
private bool areaIsDirty = true;
public void PhysicalResolutionChanged()
{
areaIsDirty = true;
}
private Rectangle area;
public void Update()
{
if (!areaIsDirty)
{
return;
}
areaIsDirty = false;
var physicalWidth = graphicsDevice.Viewport.Width;
var physicalHeight = graphicsDevice.Viewport.Height;
var physicalAspectRatio = graphicsDevice.Viewport.AspectRatio;
if ((int)(physicalAspectRatio * 10) == (int)(VirtualAspectRatio * 10))
{
area = new Rectangle(0, 0, physicalWidth, physicalHeight);
return;
}
if (VirtualAspectRatio > physicalAspectRatio)
{
var scaling = (float)physicalWidth/(float)VirtualWidth;
var width = (float)(VirtualWidth) * scaling;
var height = (float)(VirtualHeight) * scaling;
var borderSize = (int)((physicalHeight - height)/2);
area = new Rectangle(0, borderSize, (int)width, (int)height);
}
else
{
var scaling = (float)physicalHeight/(float)VirtualHeight;
var width = (float)(VirtualWidth) * scaling;
var height = (float)(VirtualHeight) * scaling;
var borderSize = (int)((physicalWidth - width)/2);
area = new Rectangle(borderSize, 0, (int)width, (int)height);
}
}
public void BeginCapture()
{
graphicsDevice.SetRenderTarget(screen);
}
public void EndCapture()
{
graphicsDevice.SetRenderTarget(null);
}
public void Draw(SpriteBatch spriteBatch)
{
spriteBatch.Draw(screen, area, Color.White);
}
}
그리고를 초기화가 같이 보일 경향이있다 :
protected override void Update(GameTime gameTime)
{
virtualScreen.Update();
base.Update(gameTime);
}
그리고 나서 그 자체를 그리는 행위 :
protected override void Draw(GameTime gameTime)
{
virtualScreen.BeginCapture();
GraphicsDevice.Clear(Color.CornflowerBlue);
// game rendering happens here...
virtualScreen.EndCapture();
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
virtualScreen.Draw(spriteBatch);
spriteBatch.End();
base.Draw(gameTime);
}
이렇게하면 기본적으로 해상도를 신경 쓰지 않고 게임에만 집중할 수 있습니다.
고맙습니다. lzcd. 이것은 정말 좋은 참고 자료이며, 두 가지 솔루션을 사용하면이 스레드가 우연히 우연히 발견되는 다른 사람들에게 도움이 될 것입니다. 네가이 시간을 가져 주셔서 감사합니다. – Xoorath
고마워요, 그게 내가 찾고 있던거야. 샘플을 가장 가깝고 선명하게 처리 할 수 있도록 고칠 수 있는지 잘 모르겠습니다. 그러나 그렇지 않다면 렌더 타겟 접근 방식을 사용합니다. – Xoorath
당신은 환영합니다 :) – Panos