gpt4 book ai didi

android - 三星更新后的错误 |单人游戏 |将 viewport.height 检测为设备宽度

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:16:19 28 4
gpt4 key购买 nike

更新

此问题也已在以下内容中讨论:https://github.com/mono/MonoGame/issues/2492

问题是如果应用程序只允许在横向运行,而不是当你使用纵向或两者都运行时。


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

我使用 GraphicsDevice.Viewport.HeightGraphicsDevice.Viewport.Width 来确定设备的分辨率。在我获得三星更新并且不得不关闭 FastDev 之前,这一直非常有效。神秘的大问题:

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

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

有人知道它是什么吗?


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

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

代码如下:

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 是实际设备高度。但是当尝试从 Samsung Galaxy S4 active 部署它时(有时您需要尝试 2-3 次)然后突然 Viewport.Height 是设备宽度,反之亦然,这使得背景图片只覆盖了一点屏幕。

已拍照展示一下:

photo

最佳答案

检查到 3.6 版本,bug 已修复。

关于android - 三星更新后的错误 |单人游戏 |将 viewport.height 检测为设备宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23978054/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com