android – 三星更新后的错误Monogame |将viewport.height检测为设备宽度

前端之家收集整理的这篇文章主要介绍了android – 三星更新后的错误Monogame |将viewport.height检测为设备宽度前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
UPDATE

这个问题也在https://github.com/mono/MonoGame/issues/2492中讨论过

问题是如果应用程序仅允许以横向方向运行,而不是在使用纵向或两者时运行.

有一个以monogame编码的安卓游戏,我得到了一个设置为FullScreen = true的GraphicsDeviceManager.

我使用GraphicsDevice.Viewport.Height和GraphicsDevice.Viewport.Width来确定设备的分辨率.
这是非常好的,直到我得到三星更新,并不得不关闭FastDev.
最大的神秘问题:

当我使用pc进行调试时,视口的高度和宽度设置正确.但是当我在视口1-2次后拔掉并播放应用程序.Height变为设备宽度,并且viewport.Width成为设备高度,这完全使游戏无法播放.

很难找到解决方案,因为当我调试并将电缆从PC连接到设备时,这种情况永远不会发生.

任何人都有任何想法可能是什么?

我现在可以确认这是因为三星更新

我制作了世界上最简单的Android应用程序来测试它,只是得到一个带有背景图像“bg”的主机和一个spritefront打印出viewport.Width和viewport.Height.

这是代码

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace TestRes
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        SpriteFont font;
        Rectangle _mainFrame;
        Texture2D _background;
        string text;

        public Game1()
        {
           graphics = new GraphicsDeviceManager(this);

            Content.RootDirectory = "Content";

            graphics.IsFullScreen = true;
            //graphics.PreferredBackBufferWidth = 800;
           // graphics.PreferredBackBufferHeight = 480;
            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting             
       /// This is where it can query for any required services and load any non-
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
           text = "";
       }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
        protected override void LoadContent()
        {
        // Create a new SpriteBatch,which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            _background = Content.Load<Texture2D>("Bilder/bg");
           _mainFrame = new Rectangle(0,this.GraphicsDevice.Viewport.Width,this.GraphicsDevice.Viewport.Height);
        // TODO: use this.Content to load your game content here
        font = Content.Load<SpriteFont>("spriteFont1");
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,/// checking for collisions,gathering input,and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
             {
                 Exit();
             }
           text = "ScreenWidth: " + this.GraphicsDevice.Viewport.Width + ",screenheight: " + this.GraphicsDevice.Viewport.Height;
        // TODO: Add your update logic here

            base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
           graphics.GraphicsDevice.Clear(Color.CornflowerBlue);

           spriteBatch.Begin();
           spriteBatch.Draw(_background,_mainFrame,Color.White);
           spriteBatch.DrawString(font,text,new Vector2(16,1000),Color.White);
           spriteBatch.End();

           base.Draw(gameTime);
       }
    }
}

从VS部署时,一切都很好,viewport.width是实际的设备宽度,viewport.height是实际的设备高度.但是当试图从三星Galaxy S4主动部署(有时你需要尝试2-3次)时,突然间Viewport.Height是设备宽度而另一种方式,这使得背景图片只是覆盖了一点的屏幕.

拍了照片来表明:

解决方法

检查版本3.6,并修复了错误.
原文链接:https://www.f2er.com/android/315008.html

猜你在找的Android相关文章