using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; namespace WinDesktopPlatformer { public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; static int PPU = 1; static int TILE_SIZE = 16; static int ROOM_WIDTH = 32; static int ROOM_HEIGHT = 18; static Rectangle CANVAS = new Rectangle(0, 0, (TILE_SIZE * ROOM_WIDTH) / PPU, (TILE_SIZE * ROOM_HEIGHT) / PPU); Texture2D tileSet; Rectangle tile1; private const int ScreenWidth = 1920; private const int ScreenHeight = 1080; private RenderTarget2D _renderTarget; public Game1() { graphics = new GraphicsDeviceManager(this); graphics.PreferMultiSampling = false; graphics.SynchronizeWithVerticalRetrace = true; graphics.PreferredBackBufferWidth = ScreenWidth; graphics.PreferredBackBufferHeight = ScreenHeight; graphics.IsFullScreen = true; Content.RootDirectory = "Content"; } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); tileSet = Content.Load(@"Images/Tiles2"); tile1 = new Rectangle(0, 32, TILE_SIZE, TILE_SIZE); _renderTarget = new RenderTarget2D(GraphicsDevice, CANVAS.Width, CANVAS.Height); } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.SetRenderTarget(_renderTarget); GraphicsDevice.Clear(Color.CornflowerBlue); // render your complete game here at a low resolution to the render target // we use point sampling here because we enlarge the texture spriteBatch.Begin(samplerState: SamplerState.PointClamp); spriteBatch.Draw(tileSet, new Rectangle(16, 16, 64, 64), tile1, Color.White); spriteBatch.End(); GraphicsDevice.SetRenderTarget(null); // here we upscale it to the full screen, again with point sampling enabled spriteBatch.Begin(samplerState: SamplerState.PointClamp); spriteBatch.Draw(_renderTarget, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White); spriteBatch.End(); base.Draw(gameTime); } } }