XNA 游戏 - 播放视频作为起始屏幕
我想播放视频作为我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
制作一个新的 IGameScreen,在启动时添加到您的游戏中。当用户按下某个键或 X 秒后(其中 X 是游戏的长度)将其转发到不同的 IGameScreen。
作为 GameScreen 对象的成员,您将需要一个 VideoPlayer 和 Video 成员。就像这样...
在您的 GameScreen LoadContent 中,您将需要加载视频,如果您尚未这样做,则创建您的 VideoPlayer 对象。就像这样......
好吧,现在在某个时候你会想要启动你的视频播放器。您可以在第一次进入时在 Update 方法中执行此操作。不要在每次更新调用时都这样做。
每次调用 Draw 方法时,您都希望从最新帧的视频播放器获取纹理,但前提是视频播放器正在播放。如果纹理已填充,则绘制它。您必须指定您希望其位于的目标矩形,或者您可以选择其他 SpriteBatch.Draw 重载之一。确保您已在代码中调用了 SpriteBatch.Begin/End 调用。
您肯定可以在代码方面进行一些改进来帮助垃圾收集器并提高性能(例如不要每次都创建一个新的矩形),但这就是显示视频的本质。
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...
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...
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.
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.
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.