XNA 游戏 - 播放视频作为起始屏幕

发布于 2024-12-04 01:45:51 字数 339 浏览 1 评论 0原文

我想播放视频作为我的 XNA 游戏开始屏幕。该游戏是一款 3D 游戏 (XNA 3.1) (基于著名的 XNA 赛车游戏 - http://exdream.com/XnaRacingGame/)。我使用 IGameScreen 界面。我想在游戏开始时播放视频(wmv格式文件)。无需全屏播放视频。

请帮帮我。 谢谢。

I want to play a video as my XNA game start Screen. The game is a 3D game (XNA 3.1) (Based on the famous XNA Racing Game - http://exdream.com/XnaRacingGame/). I use IGameScreen Interface. I want to play a video (wmv format file) with the game starting. It is not necessary to play the video in full screen.

Please, help me out.
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

饮湿 2024-12-11 01:45:51

制作一个新的 IGameScreen,在启动时添加到您的游戏中。当用户按下某个键或 X 秒后(其中 X 是游戏的长度)将其转发到不同的 IGameScreen。

作为 GameScreen 对象的成员,您将需要一个 VideoPlayer 和 Video 成员。就像这样...

VideoPlayer videoPlayer;
Video video;

在您的 GameScreen LoadContent 中,您将需要加载视频,如果您尚未这样做,则创建您的 VideoPlayer 对象。就像这样......

video = content.Load<Video>("yourvideoname");
videoPlayer = new VideoPlayer();

好吧,现在在某个时候你会想要启动你的视频播放器。您可以在第一次进入时在 Update 方法中执行此操作。不要在每次更新调用时都这样做。

videoPlayer.Play(video)

每次调用 Draw 方法时,您都希望从最新帧的视频播放器获取纹理,但前提是视频播放器正在播放。如果纹理已填充,则绘制它。您必须指定您希望其位于的目标矩形,或者您可以选择其他 SpriteBatch.Draw 重载之一。确保您已在代码中调用了 SpriteBatch.Begin/End 调用。

if(videoPlayer.State != MediaState.Stopped)
{
  Texture2D texture = videoPlayer.GetTexture();
  if(texture != null)
  {
    spriteBatch.Draw(texture, new Rectangle(0, 0, YOURWIDTH, YOURHEIGHT),
        Color.White);
  }
}

您肯定可以在代码方面进行一些改进来帮助垃圾收集器并提高性能(例如不要每次都创建一个新的矩形),但这就是显示视频的本质。

Make a new IGameScreen that is added to your Game on startup. Have it forward to a different IGameScreen when the user either hits a key or after X seconds where X is the length of your game.

As members of your GameScreen object, you will want a VideoPlayer and Video member. Like so...

VideoPlayer videoPlayer;
Video video;

In your GameScreen LoadContent you will need to load your video and if you haven't yet done so create your VideoPlayer object. Like so...

video = content.Load<Video>("yourvideoname");
videoPlayer = new VideoPlayer();

Ok, now at some point you will want to start your video player. You could do this in your Update method the first time you're in there. Don't do it on every call of the Update.

videoPlayer.Play(video)

Everytime your Draw method gets called you want to get the texture from the video player of the latest frame, but only if the video player is playing. If the texture is populated, draw it. You must specify the destination rectangle you want it to be at or you can choose one of the other SpriteBatch.Draw overloads. Make sure that you have called the SpriteBatch.Begin/End calls in your code.

if(videoPlayer.State != MediaState.Stopped)
{
  Texture2D texture = videoPlayer.GetTexture();
  if(texture != null)
  {
    spriteBatch.Draw(texture, new Rectangle(0, 0, YOURWIDTH, YOURHEIGHT),
        Color.White);
  }
}

There's definately some improvements you could do code-wise to help out the garbage collector and make this more performant (like don't create a new Rectangle everytime), but this is the low-down of showing a video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文