Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
302 views
in Technique[技术] by (71.8m points)

c# - Problem with Fullscreen Resolution in Mono Game

a couple days ago I started game developing in MonoGame with Visual Studio 2017 and porting my code which i wrote in WinForms to MonoGame. Now I have a problem with the fullscreen mode. I searched the internet and the only thing I found out is that it depends on the resolution the monitor has.

In the default window mode of the application the screen looks like follows:

enter image description here

Now when I switch to fullscreen mode - this happens:

enter image description here

Now my problems are:

  1. One can not see it on the picture because I used the print button and pasted in to paint but the image is largely strechted.
  2. The right part of the screen is cut off
  3. the sprites are moved to the top.

I'm using graphics.ToggleFullScreen();

Is there a way to keep the original status like it is in window mode? Maybe to put flexible bars for a 4:3 mode and keep the sprite positions? My positions are fixed. So use something like spriteBatch.Draw(Params.CUR_SPRITE_P1, new Rectangle(Convert.ToInt32(POSITION_P1.X), Convert.ToInt32(POSITION_P1.Y), 750, 476), Color.White); for the player position and the screen (to implement scrolling).

Or maybe adjust everything in full screen mode bu keep the positions of the sprites on different screen resolutions...

Thank you a lot!

question from:https://stackoverflow.com/questions/65926503/problem-with-fullscreen-resolution-in-mono-game

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok after searching and searching I finally found an answer:

var scaleX = (float)ActualWidth / VirtualWidth;
var scaleY = (float)ActualHeight / VirtualHeight;
var matrix = Matrix.CreateScale(scaleX, scaleY, 1.0f);

spriteBatch.Begin(transformMatrix: matrix);

This has to be put in the Draw()-Method. My virtual screensize was 800x480. I tested it with my Monitor size 1920x1080 and this did the job.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...