MonoGame 适配多种设备分辨率运行库。

NuGet:
https://www.nuget.org/packages/ScalingClever.UWP
https://www.nuget.org/packages/ScalingClever.Android
https://www.nuget.org/packages/ScalingClever.iOS
https://www.nuget.org/packages/ScalingClever.WP81

源码地址:https://github.com/chengcong/ScalingClever

功能:1.根据设备分辨率等比例放大游戏界面,全屏适配。2.触控点根据设备分辨率等比例放大,全屏适配

iOS,Android,UWP通用使用方法如下(1.0.3):

1.初始化Initialize()方法中加入:

ScalingClever.ResolutionScaling.Initialize(this, new Point(800, 480));

2.在LoadContent加入:

ScalingClever.ResolutionScaling.LoadContent(this, new Point(800, 480));

如果是UWP平台,该方法放在BeginDraw()方法中

3.重写BeginDraw()和EndDraw()

protected override bool BeginDraw()
       {
           //ScalingClever.ResolutionScaling.Initialize(this,new Point(800, 480));
           ScalingClever.ResolutionScaling.BeginDraw(this);
           return base.BeginDraw();
       }
       protected override void EndDraw()
       {
           ScalingClever.ResolutionScaling.EndDraw(this, spriteBatch);
           base.EndDraw();
       }

4.Update(GameTime gameTime)触控或点击坐标处理:

var touches = TouchPanel.GetState();

foreach (var touch in touches)

{

       if (touch.State != TouchLocationState.Pressed)
       {
       
           var postion = ScalingClever.ResolutionScaling.Position(touch.Position);
           
           var X = ScalingClever.ResolutionScaling.X(touch.Position.X);
           
           var Y = ScalingClever.ResolutionScaling.Y(touch.Position.Y);
           
                  
       }
       
}

iOS平台使用方法:

1.打开iOS项目的Program.cs文件,在FinishedLaunching(UIApplication app)的RunGame();代码后加入

ScalingClever.ResolutionScaling.FinishedLaunching(new CoreGraphics.CGSize(800, 480));

2.找到类似如下设置缓冲区尺寸的代码,删除掉。没有,请忽略。(原因:https://www.xnadevelop.com/ios/monogame-setting-buffer-size-considerations-on-the-ios-platform/

this.graphics.PreferredBackBufferWidth = 800;
this.graphics.PreferredBackBufferHeight = 480;
this.graphics.ApplyChanges();

Android平台使用方法:

1.使用通用方法1,2,3,作用是放大视图

2.找到Android项目中的Activity1.cs,在修改OnCreate方法中的代码如下所示:

protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            var g = new Game1();
            var view = (View)g.Services.GetService(typeof(View));

            //全屏放大游戏触控坐标
            var _view=ScalingClever.ResolutionScaling.OnCreate(view, new Point(800, 480));
            SetContentView(_view);
            g.Run();
        }