我在我的 XNA 项目中加载了一个视频,然后就可以播放了。唯一的问题是它被垂直切成两半。视频大小为 800x600,游戏也为 800x600。起初我不小心在我的内容中放了一个 640x480 版本的视频,但后来我将其固定为 800x600。不过,这并没有解决 1/2 垂直问题。我想也许 640x480 xnb 还在那里并且正在加载。我尝试寻找它并删除了我认为相关的所有内容,但效果不佳。这是视频的一半截图。
这是我的代码:
namespace Bloxel
{
/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public int WIDTH = 800;
public int HEIGHT = 600;
Video splash;
VideoPlayer player;
Texture2D videoTexture;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
graphics.PreferredBackBufferWidth = WIDTH;
graphics.PreferredBackBufferHeight = HEIGHT;
graphics.ApplyChanges();
}
/// <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
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);
splash = Content.Load<Video>("splash");
player = new VideoPlayer();
}
/// <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();
if (player.State == MediaState.Stopped)
{
player.IsLooped = false;
player.Play(splash);
}
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);
if (player.State != MediaState.Stopped)
videoTexture = player.GetTexture();
Rectangle screen = new Rectangle(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
if (videoTexture != null)
{
spriteBatch.Begin();
spriteBatch.Draw(videoTexture, screen, Color.White);
spriteBatch.End();
}
base.Draw(gameTime);
}
}
}