视频垂直切成XNA4 vs2012

时间:2013-08-03 01:35:47

标签: c# visual-studio-2012 xna xna-4.0

我在XNA项目中加载了一段视频,然后我开始玩了。唯一的问题是它垂直切成两半。视频大小为800x600,游戏也是800x600。起初我意外地在我的内容中放置了640x480版本的视频,但后来我将其修复为800x600。虽然没有修正1/2垂直。我想也许640x480 xnb仍然在那里并且正在加载。我试着寻找它并删除了我认为相关的任何内容,但这并没有奏效。这是视频的截图一半。

enter image description here

这是我的代码:

    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);
        }
    }
}

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

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

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

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