我有一张图片,我将其设置为使得支持的唯一方向是肖像:
关于game1()方法的 graphics.SupportedOrientations = DisplayOrientation.Portrait;
如何摆脱屏幕上下边缘的黑框?
这就是它的样子:
忽略那个29,这是我的fps监视器。
在改变方向之前:
更改后:
这是我的代码。你会注意到很多数组和添加内容,我会用它来做别的事情。现在,我并没有真正使用它:
Texture2D mineField;
Vector2 mineFieldLocation,
numFontLocation;
int[] fieldPos = new int[9];
float[]
minePosX = new float[9],
minePosY = new float[9];
SpriteFont numFont;
int posAdder = 45,
index = 0;
Random randMinePos = new Random();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.SupportedOrientations = DisplayOrientation.Portrait;
graphics.IsFullScreen = true;
// Frame rate is 30 fps by default for Windows Phone.
TargetElapsedTime = TimeSpan.FromTicks(333333);
// Extend battery life under lock.
InactiveSleepTime = TimeSpan.FromSeconds(1);
}
/// <summary>
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// 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
// le sumo o resto a la x o y 45 para que caiga en el mismo medio del cuadrado
mineFieldLocation = new Vector2(30, 70);
numFontLocation = new Vector2(33, 65);
for (int i = 0; i < fieldPos.Length; i++)
{
fieldPos[i] = posAdder;
posAdder += 45;
}
for (int i = 0; i < fieldPos.Length; i++)
{
minePosX[i] = fieldPos[randMinePos.Next(0, 9)];
minePosY[i] = fieldPos[randMinePos.Next(0, 9)];
}
base.Initialize();
}
/// <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);
mineField = Content.Load<Texture2D>("Minesweeper");
numFont = Content.Load<SpriteFont>("NumberFont");
// TODO: use this.Content to load your game content here
}
/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}
/// <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)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();
// 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)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(mineField, mineFieldLocation, Color.White);
spriteBatch.DrawString(numFont, "1", numFontLocation, Color.Green);
// spriteBatch.DrawString(numFont, "0", new Vector2(minePosX[index],minePosY[index]), Color.Black);
if (index < 8)
{
index++;
}
spriteBatch.End();
// TODO: Add your drawing code here
base.Draw(gameTime);
}
}
答案 0 :(得分:1)
正如我在评论中所说,你需要设置首选的宽度和高度,但我会解释原因..
首先,SupportedOrientations州的文件
获取或设置启用自动旋转和缩放时可用的显示方向。
我不相信你确实启用了(不确定它是否默认)。继此之后,这个页面上还有一个关于Automatic Rotation and Scaling的链接,它提供了许多关于设置宽度和高度的提示......
如果你再看一下你的第三张图片,那就有必要了,因为你当前的高度看起来像你的宽度,这让我相信你现在的宽度现在是你之前的高度。所以要确定我会设置两个
答案 1 :(得分:1)
当处于仅纵向模式时,您需要交换后缓冲区的宽度和高度值:
//For 480x800 (90* rotated wp7 device)
Graphics.PreferredBackBufferWidth = 480;
Graphics.PreferredBackBufferHeight = 800;
您在480x800屏幕上渲染了800x480后备缓冲区。这导致它成为信箱。
你可能也会对此感兴趣:
XNA - Get Current Screen Resolution
XNA: get screen's width and height