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

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

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

https://github.com/chengcong/ScalingClever

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

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

ScalingClever.ResolutionScaling.Initialize(new Point(800, 480), new Point(this.graphics.GraphicsDevice.Viewport.Width, this.graphics.GraphicsDevice.Viewport.Height));

如果是UWP平台,

ScalingClever.ResolutionScaling.Initialize(new Point(800, 480), new Point(this.Window.ClientBounds.Width, this.Window.ClientBounds.Height));

需要在Draw方法加入,实现放大缩小窗口界面自动伸缩:

ScalingClever.ResolutionScaling.Draw(new Point(800, 480), new Point(this.Window.ClientBounds.Width, this.Window.ClientBounds.Height));

注意:UWP需要安装https://www.nuget.org/packages/MonoGame.Framework.WindowsUniversal/3.5.1.1679

2.放大游戏画面:

Draw(GameTime gameTime)方法中修改 spriteBatch()为

spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScalingClever.ResolutionScaling.ScalingMatrix);

 

3.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);
           
                  
       }
       
}

 

 

原创文章,转载请注明本文链接地址(违者必究):MonoGame 适配多种设备分辨率运行库ScalingClever

打赏作者
很喜欢这篇文章,打赏犒劳下作者,以此激励作者创作更多

您的支持将鼓励我们继续创作!

[微信] 扫描二维码打赏

[支付宝] 扫描二维码打赏