Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How to realize a fixed aspect ratio window during resize in UWP

Discussion in 'Windows' started by mgoemmel, May 10, 2023.

  1. mgoemmel

    mgoemmel

    Joined:
    Sep 16, 2022
    Posts:
    10
    I'm creating a 2D board game, and want to deploy it as an UWP app in the Microsoft Store. Because it's a board game, I would need a 4:3 ration for the window, which means that what I would need is, that the user is able to size the window, but the aspect ratio of the window is always 4:3. Can this be achieved?

    I looked through a lot of internet pages, suggestions and comments, but whatever I tried so far didn't work out. Maybe I'm doing something wrong and didn't mention it.

    What I've tried so far:

    * using the Update() function, querying Screen.width and Screen.height, and if it changed to the previous values, calling SetResolution() with the 4:3 corrected values -> a lot of fllickering and window jumping

    * using UnityEngine.WSA.Application.windowSizeChanged += myWindowSizeChanged, and inside the WSA callback, calling UnityEngine.WSA.Application.InvokeOnUIThread(() with a Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().TryResizeView(new Windows.Foundation.Size { Width = w, Height = h }); call -> also a lot of flickering, and TryResizeView returns False most of the time (why?)

    Does anybody have a good idea how to achieve my goal. I would be more than happy!

    Kind regards,

    Markus