Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 SeriousGameLib;
- namespace Fotograaf
- {
- public class Fotograaf : GameWorld
- {
- public Flash Flash { get; set; }
- public Camera Camera { get; set; }
- public Cat Cat { get; set; }
- public Wallpaper Wallpaper { get; set; }
- private Texture2D _screenshotTexture;
- private RenderTarget2D[] renderBuffers;
- private int bufferIndex;
- private int previousBufferIndex;
- public Fotograaf(Game game) : base(game)
- {
- Flash = new Flash(this);
- Camera = new Camera(this);
- Cat = new Cat(this);
- Wallpaper = new Wallpaper(this);
- AddGameObject(Wallpaper);
- AddGameObject(new FPSCounter(this));
- AddGameObject(Cat);
- AddGameObject(Flash);
- AddGameObject(Camera);
- bufferIndex = 0;
- renderBuffers = new RenderTarget2D[3];
- }
- public override void Draw(GameTime gameTime)
- {
- previousBufferIndex = bufferIndex;
- if (++bufferIndex >= renderBuffers.Length) bufferIndex = 0;
- if (renderBuffers[bufferIndex] == null || Game.GraphicsDevice.Viewport.Width != renderBuffers[bufferIndex].Width || Game.GraphicsDevice.Viewport.Height != renderBuffers[bufferIndex].Height)
- renderBuffers[bufferIndex] = new RenderTarget2D(Game.GraphicsDevice, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height);
- // Set our custom render target, the entire game, during this frame, will be rendered here.
- Game.GraphicsDevice.SetRenderTarget(renderBuffers[bufferIndex]);
- base.Draw(gameTime);
- // Store a snapshot (screenshot), this is used when the player takes a picture of the animal.
- _screenshotTexture = renderBuffers[bufferIndex];
- // Restore the default render target.
- Game.GraphicsDevice.SetRenderTarget(null);
- _spriteBatch.Begin();
- // Draw the "texture" actually onscreen. The double buffer double buffered.
- _spriteBatch.Draw(renderBuffers[bufferIndex], Vector2.Zero, Color.White);
- // The camera and flash are drawn seperately, this way they wont appear on the screenshot.
- Camera.Draw(gameTime, _spriteBatch);
- Flash.Draw(gameTime, _spriteBatch);
- _spriteBatch.End();
- }
- public override void Update(GameTime gameTime)
- {
- base.Update(gameTime);
- Input.Update(gameTime);
- }
- public Texture2D getScreenShotStill()
- {
- RenderTarget2D buff = renderBuffers[previousBufferIndex];
- renderBuffers[previousBufferIndex] = null;
- return buff;
- }
- public Texture2D getScreenShotStream()
- {
- return renderBuffers[previousBufferIndex];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment