|
| 1 | +# Window Configuration |
| 2 | + |
| 3 | +<span class="badge text-bg-primary">Beginner</span> |
| 4 | + |
| 5 | +Properties of the game's window can be controled through code. |
| 6 | + |
| 7 | +Currently, this cannot be configured in Game Studio, so a simple alternative is to have a [`Startup Script`](../scripts/types-of-script#startup-scripts) in the root scene of your project, that changes values of `Game.Window`. |
| 8 | + |
| 9 | +> [!Note] |
| 10 | +> The best solution would be to change these properties before the window is opened, by overriding the `Game` class, but this is outside of the scope of this page. |
| 11 | +
|
| 12 | +```csharp |
| 13 | +using Stride.Engine; |
| 14 | + |
| 15 | +namespace MyGame |
| 16 | +{ |
| 17 | + public class WindowSetupScript : StartupScript |
| 18 | + { |
| 19 | + public override void Start() |
| 20 | + { |
| 21 | + // Set window properties here |
| 22 | + |
| 23 | + // Example |
| 24 | + Game.Window.IsBorderLess = true; |
| 25 | + } |
| 26 | + } |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +## Making the window resizable |
| 31 | + |
| 32 | +To allow for window resizing, set `AllowUserResizing` to `true`. |
| 33 | + |
| 34 | +```csharp |
| 35 | +Game.Window.AllowUserResizing = true |
| 36 | +``` |
| 37 | + |
| 38 | +## Fullscreen |
| 39 | + |
| 40 | +To enter fullscreen mode, set `IsFullscreen` to `true`. |
| 41 | + |
| 42 | +```csharp |
| 43 | +Game.Window.IsFullscreen = true |
| 44 | +``` |
| 45 | + |
| 46 | +By default, Stride uses **exclusive fullscreen**. This can be changed to **borderless fullscreen** by setting `FullscreenIsBorderlessWindow` to `true`. |
| 47 | + |
| 48 | +```csharp |
| 49 | +Game.Window.FullscreenIsBorderlessWindow = true; |
| 50 | +``` |
| 51 | + |
| 52 | +The main difference between these two fullscreen modes is that **exclusive fullscreen** renders the game directly to the screen, while **borderless fullscreen** resizes the window to take up the entire display. |
| 53 | + |
| 54 | +> [!Note] |
| 55 | +> **Exclusive fullscreen** can slightly improve performence, but is generally disliked by most players due to making switching between different applications slower and more cumbersome. |
| 56 | +
|
| 57 | +## Resolution |
| 58 | + |
| 59 | +Resolution can be set using the `SetSize` method and read using the `ClientBounds` property. |
| 60 | + |
| 61 | +```csharp |
| 62 | +// Setting the window size to 1920x1080 |
| 63 | +Game.Window.SetSize(new Int2(1920, 1080)); |
| 64 | + |
| 65 | +// Reading window size and position |
| 66 | +var newBounds = Game.Window.ClientBounds; |
| 67 | +``` |
| 68 | + |
| 69 | +The size of the entire screen can be found in `Game.GraphicsDevice`. |
| 70 | + |
| 71 | +```csharp |
| 72 | +// List of all connected displays |
| 73 | +var monitors = Game.GraphicsDevice.Outputs; |
| 74 | + |
| 75 | +// Reading the size and position of the first connected display |
| 76 | +var bounds = monitors[0].DesktopBounds; |
| 77 | +``` |
| 78 | + |
| 79 | +Each output also contains a list of supported display modes for the monitor. This is useful for **creating a resolution dropdown** in a settings menu of your game. |
| 80 | + |
| 81 | +```csharp |
| 82 | +var supportedDisplayModes = monitors[0].SupportedDisplayModes; |
| 83 | + |
| 84 | +// Create a list of avaliable resolutions |
| 85 | +var resolutions = new List<Int2>(); |
| 86 | +foreach (var mode in supportedDisplayModes) |
| 87 | +{ |
| 88 | + var res = new Int2(mode.Width, mode.Height); |
| 89 | + if (!resolutions.Contains(res)) |
| 90 | + resolutions.Add(res); |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## Title |
| 95 | + |
| 96 | +The window title can be changed using the `Title` property. |
| 97 | + |
| 98 | +```csharp |
| 99 | +Game.Window.Title = "My Title Here"; |
| 100 | +``` |
| 101 | + |
| 102 | +## Other window properties |
| 103 | + |
| 104 | +Here are other miscellaneous window properties. |
| 105 | + |
| 106 | +```csharp |
| 107 | +// Changes window opacity |
| 108 | +Game.Window.Opacity = 0.6f; |
| 109 | + |
| 110 | +// Removes window borders |
| 111 | +Game.Window.IsBorderless = true; |
| 112 | + |
| 113 | +// Changes mouse visibility |
| 114 | +Game.Window.IsMouseVisible = false; |
| 115 | + |
| 116 | +// Changes the position of the window |
| 117 | +Game.Window.Position = new Int2(50, 50); |
| 118 | + |
| 119 | + |
| 120 | +// True when the window has focus |
| 121 | +var hasFocus = Game.Window.IsFocused; |
| 122 | + |
| 123 | +// True when the window is minimized |
| 124 | +var minimized = Game.Window.IsMinimized; |
| 125 | +``` |
0 commit comments