Advertisement
SilverTES

Retro2D : Minimal Code + FPS + Mouse

Dec 12th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.95 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using Retro2D;
  5.  
  6. namespace StarterGame
  7. {
  8.     public class Game1 : Game
  9.     {
  10.         Window _window = new Window();
  11.         FrameCounter _frameCounter = new FrameCounter();
  12.         MouseState _mouseState;
  13.         int _relMouseX;
  14.         int _relMouseY;
  15.         int _screenW = 960;
  16.         int _screenH = 540;
  17.  
  18.         public int _finalScreenW = 960;
  19.         public int _finalScreenH = 540;
  20.  
  21.         public Game1()
  22.         {
  23.             _window.Setup(this, Mode.RETRO, "StarterGame", _screenW, _screenH, 2, 0, false, true, false);
  24.             Content.RootDirectory = "Content";
  25.         }
  26.         protected override void Initialize()
  27.         {
  28.             _window.Init();
  29.             _window.SetScale(2);
  30.  
  31.             _window.SetFinalScreenSize(_finalScreenW, _finalScreenH);
  32.  
  33.             base.Initialize();
  34.         }
  35.         protected override void LoadContent()
  36.         {
  37.         }
  38.         protected override void UnloadContent()
  39.         {
  40.         }
  41.         protected override void Update(GameTime gameTime)
  42.         {
  43.             _window.GetMouse(ref _relMouseX, ref _relMouseY, ref _mouseState);
  44.  
  45.             if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  46.                 Exit();
  47.  
  48.             _window.UpdateStdWindowControl();
  49.  
  50.             _frameCounter.Update(gameTime);
  51.  
  52.             Window.Title = "FPS :" + _frameCounter.Fps();
  53.  
  54.             base.Update(gameTime);
  55.         }
  56.         protected override void Draw(GameTime gameTime)
  57.         {
  58.  
  59.             // Set Target to MainRenderTarget !
  60.             _window.SetRenderTarget(_window.NativeRenderTarget);
  61.             _window.Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.PointClamp); //, DepthStencilState.None, RasterizerState.CullCounterClockwise );
  62.  
  63.             // Draw something here !
  64.             _window.Batch.GraphicsDevice.Clear(new Color(20, 40, 60));
  65.             Retro2D.Draw.Grid(_window.Batch, 0, 0, _screenW, _screenH, 16, 16, Color.Gray * .4f);
  66.             Retro2D.Draw.Sight(_window.Batch, _relMouseX, _relMouseY, _screenW, _screenH, Color.RoyalBlue, 1);
  67.  
  68.             _window.Batch.End();
  69.  
  70.             // Render MainTarget in FinalTarget
  71.             _window.SetRenderTarget(_window.FinalRenderTarget);
  72.             _window.Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.AnisotropicClamp);
  73.  
  74.             _window.RenderMainTarget(Color.White);
  75.  
  76.             _window.Batch.End();
  77.  
  78.             // Flip to FinalRenderTarget !
  79.             _window.SetRenderTarget(null);
  80.             _window.Batch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.AnisotropicClamp);
  81.  
  82.             _window.RenderFinalTarget(Color.White);
  83.  
  84.             _window.Batch.End();
  85.  
  86.  
  87.             base.Draw(gameTime);
  88.         }
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement