Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public override void Draw(TimeSpan dt)
- {
- if (!hasBuffer)
- {
- DrawSceneToTexture(currentRenderTarget, DrawRectangles);
- DrawSceneToTexture(secondRenderTarget, DrawAnimatedRectangles, dt);
- hasBuffer = true;
- }
- GraphicsDevice.Clear(Color.Transparent);
- DrawAnimatedRectangles(dt, new Vector2(200, 100), Color.OrangeRed);
- spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
- spriteBatch.Draw(currentRenderTarget,new Rectangle(0,0,150,678),Color.White);
- spriteBatch.Draw(textureCustom,Vector2.Zero, Color.White);
- spriteBatch.Draw(secondRenderTarget, Vector2.Zero, Color.White);
- spriteBatch.End();
- if (index == 2)
- {
- hasBuffer = false;
- index = 0;
- }
- index++;
- //base.Draw(gameTime);
- }
- /// <summary>
- /// Draws the entire scene in the given render target.
- /// </summary>
- /// <returns>A texture2D with the scene drawn in it.</returns>
- protected void DrawSceneToTexture(RenderTarget2D renderTarget, Action DrawAction)
- {
- // Set the render target
- GraphicsDevice.SetRenderTarget(renderTarget);
- GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
- // Draw the scene
- GraphicsDevice.Clear(Color.Transparent);
- DrawAction();
- // Drop the render target
- GraphicsDevice.SetRenderTarget(null);
- }
- private void DrawSceneToTexture(RenderTarget2D renderTarget, Action<TimeSpan, Vector2, Color> DrawAction, TimeSpan dt)
- {
- // Set the render target
- GraphicsDevice.SetRenderTarget(renderTarget);
- GraphicsDevice.DepthStencilState = new DepthStencilState() { DepthBufferEnable = true };
- // Draw the scene
- GraphicsDevice.Clear(Color.Transparent);
- DrawAction(dt, new Vector2(100, 100), Color.BlueViolet);
- // Drop the render target
- GraphicsDevice.SetRenderTarget(null);
- }
- void DrawRectangles()
- {
- spriteBatch.Begin();
- spriteBatch.Draw(textureCustom, new Vector2(50, 50), new Rectangle(0, 0, 200, 50), Color.Red);
- spriteBatch.Draw(textureCustom, new Vector2(50, 150), new Rectangle(0, 0, 200, 50), Color.Green);
- spriteBatch.End();
- }
- void DrawAnimatedRectangles(TimeSpan dt, Vector2 position, Color color)
- {
- spriteBatch.Begin();
- spriteBatch.Draw(
- texture,
- position,
- new Rectangle(0, 0, 5, 90),
- color,
- MathHelper.ToRadians((float)dt.TotalMilliseconds * 0.3f),
- new Vector2(2.5f, 0),
- 1.0f,
- SpriteEffects.None,
- 1f);
- spriteBatch.End();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement