Using 2D sprites and 3D models together

Posted by Sweta Dwivedi on Game Development See other posts from Game Development or by Sweta Dwivedi
Published on 2012-10-08T14:00:56Z Indexed on 2012/10/08 15:54 UTC
Read the original article Hit count: 321

Filed under:

I have gone through a few posts that talks about changing the GraphicsDevice.BlendState and GraphicsDevice.DepthStencilState (SpriteBatch & Render states). . however even after changing the states .. i cant see my 3D model on the screen.. I see the model for a second before i draw my video in the background. . Here is the code:

 case GameState.InGame:

           GraphicsDevice.Clear(Color.AliceBlue);

           spriteBatch.Begin();

          if (player.State != MediaState.Stopped)
           {
              videoTexture = player.GetTexture();
            }

       Rectangle screen = new Rectangle(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);


        // Draw the video, if we have a texture to draw.
          if (videoTexture != null)
          {

             spriteBatch.Draw(videoTexture, screen, Color.White);

          if (Selected_underwater == true)
          {
            spriteBatch.DrawString(font, "MaxX , MaxY" + maxWidth + "," + maxHeight, new Vector2(400, 10), Color.Red);
         spriteBatch.Draw(kinectRGBVideo, new Rectangle(0, 0, 100, 100), Color.White);
         spriteBatch.Draw(butterfly, handPosition, Color.White);

              foreach (AnimatedSprite a in aSprites)
              {
                a.Draw(spriteBatch);
              }

            }

           if(Selected_planet == true)
           {

             spriteBatch.Draw(kinectRGBVideo, new Rectangle(0, 0, 100, 100), Color.White);
             spriteBatch.Draw(butterfly, handPosition, Color.White);
             spriteBatch.Draw(videoTexture,screen,Color.White);

             GraphicsDevice.BlendState = BlendState.Opaque;
             GraphicsDevice.DepthStencilState = DepthStencilState.Default;
             GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap;

              foreach (_3DModel m in Solar)
              {
                     m.DrawModel();
              }
            }
            spriteBatch.End();
            break;

© Game Development or respective owner

Related posts about xna-4.0