2014-04-14 5 views
1

나는 Windows Phone에서 내 Store Shooter 게임을 Windows Store App으로 이식하고 있습니다. WP에서는 항상 세로 방향으로 재생됩니다.SwapChainBackgroundPanel 레터 박스 Monogame Windows 스토어 앱

가로 모드에서는 Windows 저장소 앱의 경우 왼쪽과 오른쪽에 레터 박스가있는 게임 화면을 가운데에 배치하려고합니다. 문제는 SwapChainBackgroundPanel의 여백 속성을 조정할 수 없기 때문에 게임이 항상 왼쪽으로 정렬되고 검은 색 화면이 오른쪽에 정렬됩니다.

여기 GamePage.xaml 일부는 내가 this blog post 덕분에 그것을 알아 낸 것 같아요 조사 후 기본

<SwapChainBackgroundPanel 
    x:Class="SpaceShooterXW8.GamePage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:SpaceShooterXW8" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d">  
</SwapChainBackgroundPanel> 
+1

다음 사용하여 마우스 입력을 확장하기 위해 관리했습니다

업데이트. 'SwapChainBackgroundPanel'은 8.1 이후에 사용할 수 없거나 변경되지 않으며 [SwapChainPanel] (http://msdn.microsoft.com/en-us/library/windows/apps/windows)로 전환하라는 메시지가 표시됩니다. 대신 ui.xaml.controls.swapchainpanel)을 사용하십시오. –

답변

0

내 코드

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.AppWidthGame1.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.AppHeightGamePage.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; 
    }