1

我在我的 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);
        }
    }
}
4

2 回答 2

2

正如迈克所说,这个问题是由系统更新引起的。为了解决此问题,您需要进入 Windows 更新并删除“Windows 7 安全更新 (KB2803821)”。您只需右键单击更新并按删除即可完成此操作。

于 2013-08-04T00:26:28.760 回答
0

我不知道这是否可行,但您可以尝试一下:将您的矩形更改为绘图函数中的向量。

spriteBatch.Draw(videoTexture, Vector2.Zero, Color.White);

因为 Vector2 为零,它会出现在游戏屏幕的一角。

于 2013-08-03T07:30:41.613 回答