2014-05-16 3 views
1

게임에 비디오를 두 개 이상 추가하는 데 어려움이 있습니다. 첫 번째 동영상은 메뉴를 표시하기 전에 완벽하게 재생됩니다 (introVid). start를 누르면 두 번째 비디오 (level0로드 전)가 표시되는 대신 vidTexture2가 NULL이라는 오류가 발생합니다.하나 이상의 비디오 추가

둘 이상의 비디오를 추가하는 방법에 대해 아는 사람이 있습니까?

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 

    } 
} 

및 GAME1 : 여기에 비디오 관리자 클래스의 코드입니다

using System; 
using System.Collections.Generic; 
using System.Linq; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.GamerServices; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using Microsoft.Xna.Framework.Media; 
using TileEngine; 
using TimerGame.MenuButtons; 
using TimerGame.LevelManagers; 
using TimerGame.VideoManagers; 

namespace TimerGame 
{ 
    public class Game1 : Microsoft.Xna.Framework.Game 
    { 
     GraphicsDeviceManager graphics; 
     SpriteBatch spriteBatch; 

     Player player; 
     SpriteFont pericles10; 

     //MENU 

     ... 

     Video1Manager videoManager; 

     //Levels 

     int currentLevel = -1; 

     int state = 0; 


     ... 


     protected override void Initialize() 
     { 

      videoManager = new Video1Manager(); 

      ... 
     } 


     protected override void LoadContent() 
     { 
      spriteBatch = new SpriteBatch(GraphicsDevice); 


     ... 

      //Video 

      videoManager.Initialize(Content); 

      if (state == 0) 
       videoManager.PlayIntro(); 


      ... 


     } 

     protected override void Update(GameTime gameTime) 
     { 

      ... 

      switch (state) 
      { 
       case 0: 
        if (keyState.IsKeyDown(Keys.Escape)) 
        { 
         videoManager.vidPlayer.Stop(); 
         state = 1; 
        } 
        if (videoManager.vidPlayer.State == MediaState.Stopped) 
        { 
         state = 1; 
         MediaPlayer.Play(menuMusic); 
        } 

        break; 

       case 1: 

        ... 

         #region Playing 

         case GameState.Playing: 
          IsMouseVisible = false; 

          ... 
           switch (currentLevel) 
           { 
            case 0: 

             videoManager.PlayCine1(); 

             if (videoManager.vidPlayer2.State == MediaState.Stopped) 
             { 
              currentLevel++; 
              Level0Manager.LoadLevel(); 
             } 

             break; 

            case 1: 

             player.Update(gameTime); 
             Level0Manager.Update(gameTime); 
             if (Level0Manager.LevelComplete) 
             { 
              currentLevel++; 
             } 

             break; 

            ...some code 

         #endregion 
        } 

        break; 

      } 

      base.Update(gameTime); 
     } 


     protected override void Draw(GameTime gameTime) 
     { 

      GraphicsDevice.Clear(Color.Black); 


      videoManager.vidTexture = videoManager.vidPlayer.GetTexture(); //Video TEXTURE    


      spriteBatch.Begin(
       SpriteSortMode.BackToFront, 
       BlendState.AlphaBlend);    

      switch (state) 
      { 
       case 0: 
        spriteBatch.Draw(videoManager.vidTexture, videoManager.vidRectangle, Color.White); 

        break; 

       case 1: 

        switch (gameState) 
        { 

         #region Menu Draw 

         ... 

          break; 

         #endregion 

         #region Playing Draw 

         case GameState.Playing: 

          MediaPlayer.Stop(); 
          //spriteBatch.DrawString(pericles10, "12:20", new Vector2(100, 20), Color.Red); 
          TileMap.Draw(spriteBatch); 

          switch (currentLevel) 
          { 
           case 0: 
            videoManager.vidTexture2 = videoManager.vidPlayer2.GetTexture();          
            spriteBatch.Draw(videoManager.vidTexture2, videoManager.vidRectangle2, Color.White); 

            break; 

           case 1: 
            player.Draw(spriteBatch); 
            Level0Manager.Draw(spriteBatch); 
            break; 

           ....other code 

          break; 

         #endregion 

        } 

        break; 
      } 

      spriteBatch.End(); 


      base.Draw(gameTime); 

     } 
    } 
} 
+0

그냥 힌트 : 당신은 당신의 코드와 질문을 단순화 경우에 당신은 아마 더 답변을 얻을 것이다. – FunctionR

+0

당신이 말하는데 - 두 번째'Texture2D vidTexture2'를 할 때,'vidTexture2가 NULL '이라는 두 번째 비디오가 재생되어야 할 때 항상 나를 게임에서 제외시킵니다. 나는 당신의 코드에서'Texture2D vidTexture2'를 보지 못합니다. xD – Wallstrider

+0

@FunctionR 귀하의 제안을 볼 수는 있지만, 왜 XNA 4.0을 제목에서 삭제합니까? – Chipnstein3D

답변

0

당신은 텍스처가 null가 아닌 경우 확인해야한다, 나는 당신이 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(); 
} 

출처 : http://msdn.microsoft.com/en-us/library/dd904198.aspx

관련 문제