C# 添加多个视频
我很难在游戏中添加多个视频。在显示菜单之前,第一个视频将完美播放(introVid)。一旦我按下开始键,而不是显示第二个视频(在0级加载之前),我会得到一个错误,说vidTexture2为空 有人知道如何添加多个视频吗?以下是视频管理器类的代码:C# 添加多个视频,c#,video,xna,C#,Video,Xna,我很难在游戏中添加多个视频。在显示菜单之前,第一个视频将完美播放(introVid)。一旦我按下开始键,而不是显示第二个视频(在0级加载之前),我会得到一个错误,说vidTexture2为空 有人知道如何添加多个视频吗?以下是视频管理器类的代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xna.Framework; using Mic
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using TileEngine;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;
namespace TimerGame.VideoManagers
{
public class Video1Manager
{
#region Declarations
public Video introVid, cineVid;
public VideoPlayer vidPlayer, vidPlayer2;
public Texture2D vidTexture, vidTexture2;
public Rectangle vidRectangle, vidRectangle2;
#endregion
#region Initialization
public void Initialize(ContentManager Content)
{
try
{
vidPlayer = new VideoPlayer();
vidPlayer2 = new VideoPlayer();
introVid = Content.Load<Video>(@"Videos\TimerIntro");
vidRectangle = new Rectangle(-225, 0,
1250, 600);
cineVid = Content.Load<Video>(@"Videos\Cinematic1");
vidRectangle2 = new Rectangle(0, 0, 800, 600);
}
catch { Debug.Write("Video Manager Failed"); }
}
public void PlayIntro()
{
try { vidPlayer.Play(introVid); }
catch { Debug.Write("IntroVid Failed"); }
}
public void PlayCine1()
{
try { vidPlayer2.Play(cineVid); }
catch { Debug.Write("Cinematic1 Failed"); }
}
#endregion
}
}
你必须检查纹理是否不为空,我建议你检查下面链接的msdn msdn中的代码段:
// Draw the video, if we have a texture to draw.
if (videoTexture != null)
{
spriteBatch.Begin();
spriteBatch.Draw(videoTexture, screen, Color.White);
spriteBatch.End();
}
来源:只是一个提示:如果你简化你的代码和问题,那么你可能会得到更多的答案。你说-当我做第二个
Texture2D vidTexture2
,当第二个视频应该播放时,它总是让我退出游戏,说vidTexture2为空。我甚至没有在您的代码中看到Texture2D vidTexture2
。xD@FunctionR我明白你的建议,但是,为什么要从标题中删除XNA 4.0?你已经把它作为标签了,所以在标题中不需要它。这是堆栈溢出准则的一部分。@Wallstarder抱歉,我在复制粘贴代码时尝试了一些新的东西。现在应该好了
// Draw the video, if we have a texture to draw.
if (videoTexture != null)
{
spriteBatch.Begin();
spriteBatch.Draw(videoTexture, screen, Color.White);
spriteBatch.End();
}