내 코드
public Game1()
{
graphics = new GraphicsDeviceManager(this);
GamePage.Current.SizeChanged += OnWindowSizeChanged;
Content.RootDirectory = "Content";
}
private void OnWindowSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e)
{
var CurrentViewState = Windows.UI.ViewManagement.ApplicationView.Value;
double width = e.NewSize.Width;
double height = e.NewSize.Height;
// using Windows.Graphics.Display;
ResolutionScale resolutionScale = DisplayProperties.ResolutionScale;
string orientation = null;
if (ApplicationView.Value == ApplicationViewState.FullScreenLandscape)
{
orientation = "FullScreenLandscape";
//Does not work because it's start on the center of the screen
//Black screen is on the left and place the game screen on the right
GamePage.Current.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
//Gives error - WinRT information: Setting 'Margin' property is
//not supported on SwapChainBackgroundPanel.
GamePage.Current.Margin = new Thickness(centerMargin, 0, 0, 0);
}
else if (ApplicationView.Value == ApplicationViewState.FullScreenPortrait)
{
orientation = "FullScreenPortrait";
}
else if (ApplicationView.Value == ApplicationViewState.Filled)
{
orientation = "Filled";
}
else if (ApplicationView.Value == ApplicationViewState.Snapped)
{
orientation = "Snapped";
}
Debug.WriteLine("{0} x {1}. Scale: {2}. Orientation: {3}",
width.ToString(), height.ToString(), resolutionScale.ToString(),
orientation);
}
입니다. 비슷한 상황에 처한 사람들에게 내가 한 일이 여기있다.
해결책의 장점은 레터 박스가 Resolution
클래스에 의해 자동 관리된다는 것입니다. 방향이 내가 App.AppWidth
내 Game1.cs
public Game1()
{
graphics = new GraphicsDeviceManager(this);
GamePage.Current.SizeChanged += OnWindowSizeChanged;
Content.RootDirectory = "Content";
Resolution.Init(ref graphics);
Resolution.SetVirtualResolution(480, 800);
}
private void OnWindowSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs e)
{
var CurrentViewState = Windows.UI.ViewManagement.ApplicationView.Value;
App.AppWidth = (int)e.NewSize.Width;
App.AppHeight = (int)e.NewSize.Height;
Resolution.SetResolution(App.AppWidth, App.AppHeight, true);
}
초기 값이를 사용하여 변경된 것으로 내가 할 일은 해상도 변경을 처리하기 위해
batch.Begin(SpriteSortMode.Deferred,
null, SamplerState.LinearClamp,
null,
null,
null,
Resolution.getTransformationMatrix());
처럼 뭔가 내 코드에서 batch.begin()
라인을 업데이트하고 App.AppHeight
은 GamePage.xaml.cs
에 설정됩니다.
public GamePage(string launchArguments)
{
this.InitializeComponent();
App.AppWidth = (int)Window.Current.Bounds.Width;
App.AppHeight = (int)Window.Current.Bounds.Height;
Current = this;
// Create the game.
_game = XamlGame<Game1>.Create(launchArguments, Window.Current.CoreWindow, this);
}
두
가
App.xaml.cs
public static int AppWidth { get; set; }
public static int AppHeight { get; set; }
내가 지금까지 만난 유일한 문제에서 만든 글로벌 정적 재산, 마우스 입력은 화면 해상도 변경에 확장되지 않습니다. 불행히도 테스트 할 터치 스크린이 없지만 터치 입력이 확장되어야한다고 생각합니다. 누구든지 접촉을 테스트 한 경우 결과를 공유하십시오. 감사. 난 그냥 당신이 포팅하는 동안 고려해야 할 보조 노트로
public static Vector2 ScaleGesture(Vector2 position)
{
int x = (int)(position.X/(float)App.AppWidth * (float)Screen.ScreenWidth);
int y = (int)(position.Y/(float)App.AppHeight * (float)Screen.ScreenHeight);
var scaledPosition = new Vector2(x, y);
return scaledPosition;
}
다음 사용하여 마우스 입력을 확장하기 위해 관리했습니다
업데이트. 'SwapChainBackgroundPanel'은 8.1 이후에 사용할 수 없거나 변경되지 않으며 [SwapChainPanel] (http://msdn.microsoft.com/en-us/library/windows/apps/windows)로 전환하라는 메시지가 표시됩니다. 대신 ui.xaml.controls.swapchainpanel)을 사용하십시오. –