Advertisement
Guest User

Untitled

a guest
Nov 20th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.11 KB | None | 0 0
  1.         public override void Draw(TimeSpan dt)
  2.         {
  3.             if (!hasBuffer)
  4.             {
  5.                 DrawSceneToTexture(currentRenderTarget, DrawRectangles);
  6.                 DrawSceneToTexture(secondRenderTarget, DrawAnimatedRectangles, dt);
  7.                 hasBuffer = true;
  8.             }
  9.            
  10.             GraphicsDevice.Clear(Color.Transparent);
  11.  
  12.             DrawAnimatedRectangles(dt, new Vector2(200, 100), Color.OrangeRed);
  13.  
  14.  
  15.             spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
  16.  
  17.             spriteBatch.Draw(currentRenderTarget,new Rectangle(0,0,150,678),Color.White);
  18.             spriteBatch.Draw(textureCustom,Vector2.Zero, Color.White);
  19.             spriteBatch.Draw(secondRenderTarget, Vector2.Zero, Color.White);
  20.             spriteBatch.End();
  21.             if (index == 2)
  22.             {
  23.                 hasBuffer = false;
  24.                 index = 0;
  25.             }
  26.             index++;
  27.             //base.Draw(gameTime);
  28.         }
  29.  
  30.  
  31.         /// <summary>
  32.         /// Draws the entire scene in the given render target.
  33.         /// </summary>
  34.         /// <returns>A texture2D with the scene drawn in it.</returns>
  35.         protected void DrawSceneToTexture(RenderTarget2D renderTarget, Action DrawAction)
  36.         {
  37.             // Set the render target
  38.             GraphicsDevice.SetRenderTarget(renderTarget);
  39.  
  40.             GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
  41.  
  42.             // Draw the scene
  43.             GraphicsDevice.Clear(Color.Transparent);
  44.  
  45.             DrawAction();
  46.  
  47.             // Drop the render target
  48.             GraphicsDevice.SetRenderTarget(null);
  49.         }
  50.  
  51.         private void DrawSceneToTexture(RenderTarget2D renderTarget, Action<TimeSpan, Vector2, Color> DrawAction, TimeSpan dt)
  52.         {
  53.             // Set the render target
  54.             GraphicsDevice.SetRenderTarget(renderTarget);
  55.  
  56.             GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
  57.  
  58.             // Draw the scene
  59.             GraphicsDevice.Clear(Color.Transparent);
  60.  
  61.             DrawAction(dt, new Vector2(100, 100), Color.BlueViolet);
  62.  
  63.             // Drop the render target
  64.             GraphicsDevice.SetRenderTarget(null);
  65.         }
  66.  
  67.         void DrawRectangles()
  68.         {
  69.             spriteBatch.Begin();
  70.             spriteBatch.Draw(textureCustom, new Vector2(50, 50), new Rectangle(0, 0, 200, 50), Color.Red);
  71.             spriteBatch.Draw(textureCustom, new Vector2(50, 150), new Rectangle(0, 0, 200, 50), Color.Green);
  72.             spriteBatch.End();
  73.         }
  74.  
  75.         void DrawAnimatedRectangles(TimeSpan dt, Vector2 position, Color color)
  76.         {
  77.             spriteBatch.Begin();
  78.             spriteBatch.Draw(
  79.                 texture,
  80.                 position,
  81.                 new Rectangle(0, 0, 5, 90),
  82.                 color,
  83.                 MathHelper.ToRadians((float)dt.TotalMilliseconds * 0.3f),
  84.                 new Vector2(2.5f, 0),
  85.                 1.0f,
  86.                 SpriteEffects.None,
  87.                 1f);
  88.             spriteBatch.End();
  89.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement