XNA Viewport confusion - c#

I want the game to adapt to the screen resolution, but I want the viewport to always stay the same, so the game basically just resizes itself when running on different PCs. How do I do it?
So, for example, screen resolution is 1920x1080 and the viewport is 640x480. How do I stretch those 640x480 onto 1920x1080? Is that even possible?
If this did not make any sense, I'll try to explain another way.
Thanks in advance!

Related

How to set portrait aspect ratio for Windows build in Unity

I'm trying to build a unity project for standalone and the game is in portrait configuration. Everything works fine when I test it in the editor, but when I build it, everything UI related is messed up and by that I mean it tries to fit to the screen's aspect ratio causing many buttons and UI elements to be off-screen despite even manually trying to change the screen size by doing Screen.SetResolution(1080, 1920, false); and stopping the game from entering full-screen mode in the build settings so that it would become a portrait aspect ratio but nothing is working. The game itself is working fine which is not a part of UI or any canvas obviously. Any help would be much appreciated!
UI scaling is tricky particularly is you have different aspect ratios, and also if you have different resolutions (although they are different). The most important things from my experience are making sure you've anchored things as reasonably as you can, used layout groups for dynamic content (dropdowns, instantiated elements, etc.) and used the CanvasScaler component on your canvas.
The Canvas Scaler component can be found on your canvas object in the scene, and is the first place to start when dealing with variable screen sizes. . This mode is the best for variable screen sizes, you can set this up to be your preferred screen size and then make your UI fit that size, then automatically scale based on your ideal size.
It's hard to say what is the best way to anchor your UI elements generally speaking, but if you don't want them centred on the middle of the screen it likely isn't the default. I often find anchoring the sides of an area, or corners, is best.
Finally, depending on your platform and handled screen orientations, you can also set device orientation preferences in Player Preferences. . Exactly what you set may depend on your project, but can be an important step in making sure your UI scales correctly for you targets.

How to make Unity Game fit any resolution when resizing the window?

I couldn't find an option to send a picture to better explain what's happening. Here's a Unity Link that has the photos to explain the issue.
I've tried Camera.main.orthographicsize = 4.0f, a solid number to stay on but the Orthographic Size of the camera keeps changing it's size after resizing the window when I'm in free aspect Unity editor mode and even when I export the Unity game with 1920x1080(16:9) resolution. I want it to stay the same size when resizing the window so that the game can always fit inside the screen in any resolution when resizing the window. The default blue background of the camera displays when I stretch the window's width far enough which I don't want to happen.
This Youtube video has the results I'm looking for but the code unfortunately is not working on Unity 2019. The code provided from this video does entirely different things for me and doesn't solve my issue.
From what I understood is that the screen has to has a fixed resolution.
This link will demonstrate the solution. https://docs.unity3d.com/Manual/GameView.html
It does that by changing the
Game View Aspect from free to a fixed resolution.
Unless this is not what you are looking for then I sugest another solution:
Make a black background image that fits the screen size.
Then change the scale of the objects in the scene relative to the camera.
This link will make the scaling solution, Make object visual size constant despite the distance

C# OpenTk scale object with on screen resize and camera size

Look at the those images minimized fullscreen
The minimized window created with 2 texture is right, but in the fullscreen window i dont know how to fix, i dont know if i should scale the texture or zoom the camera but im noob with opentk, if someone can help me with some code. I dont post any code becouse i dont really know how to fix it..
Thanks and sorry for my english!
You need to use the OnResize method and change the projection matrix
In OpenGL, how can I adjust for the window being resized?
If you are using immediate mode then this will help, other wise you will need to change the projection matrix in the shaders you are using.

Some objects vanish when window is minimized in my XNA game

I'm building a game in XNA 4.0 and C# and am running into an issue when I try to make the game run fullscreen or when I minimize the window and bring it back. Basically, one of the objects in my game (the doors), always vanish and do not come back.
Does anyone know what exactly happens when the window is minimized and why the door may be behaving differently than other elements in the game?
Check the update and draw loops and make sure your doors are being both updated and redrawn.
When you change the size of the window and objects disappear, there is usually an error somewhere with the redrawing of the frame.
I solved this problem and it was very tricky. What happened had to do with window resizing, as I was using 1366 x 768 when my computer's monitor is only 1280 x 800. Naturally, some of the game is always clipped, but on minimizing, the clipping changed very subtley.
The best fix was to just start putting elements within my own screen resolution. I'm now coding assuming a resolution of 1280 x 768.

c# how to perform a screen clipping similar to OneNote Windows + S shortcut key

I'd like to implement a similar screen clipping functionality to that of OneNote. Basically it can draw a translucent overlay on top of the whole screen, and also freeze the screen so users can clip a portion of it.
I've done some research around and it seems that the easiest way is to create a translucent TopMost form with the size of the whole screen and then perform clipping on this form. This approach, however, is slow. I see some other suggestions about doing a Direct3D hook for drawing overlay, but this is probably too complicated and I'm not sure how stable it is with respect to different Direct3D version. Any ideas how OneNote does it?
I think instead of creating the transparent layer on top of the screen, just grab a screenshot of the whole screen and make it full screen. So users are drawing on a static image not a translucent layer. Since it is a screenshot already, it is already frozen. I think this is how they do it anyway, I doubt an application can simply freeze a screen, they take a photo of it and cover your screen with it, so its as if its frozen.

Categories