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

时间:2014-06-01 08:32:49

标签: android xamarin resolution monogame

更新

此问题也在https://github.com/mono/MonoGame/issues/2492

中讨论过

问题在于,只允许应用程序以横向方向运行,而不是在使用纵向或两者都运行时。


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

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

当我使用电脑进行调试时,viewport的高度和宽度设置正确。但是当我在1-2次后拔掉并播放应用程序时,viewport.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, 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是设备宽度而另一种方式,这使得背景图片只是覆盖了一点屏幕。

拍了照片来表明:

photo

1 个答案:

答案 0 :(得分:0)

在版本3.6中检查,并修复了错误。