/// <summary> /// Takes screen coordinates (2D position like where the mouse is on screen) then converts it to world position (where we clicked at in the world). /// </summary> private static Vector2 ScreenToWorld(Vector2 input) { input.X -= Resolution.VirtualViewportX; input.Y -= Resolution.VirtualViewportY; return(Vector2.Transform(input, Matrix.Invert(Camera.GetTransformMatrix()))); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); Resolution.BeginDraw(); // TODO: Add your drawing code here spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Camera.GetTransformMatrix()); DrawObjects(); map.DrawWalls(spriteBatch); spriteBatch.End(); gameHUD.Draw(spriteBatch); base.Draw(gameTime); }
/// <summary> /// This is called when the game is ready to draw to the screen, it's also called each frame. /// </summary> protected override void Draw(GameTime gameTime) { //This will clear what's on the screen each frame, if we don't clear the screen will look like a mess: GraphicsDevice.Clear(Color.CornflowerBlue); Resolution.BeginDraw(); spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Camera.GetTransformMatrix()); DrawObjects(); map.DrawWalls(spriteBatch); spriteBatch.End(); gameHUD.Draw(spriteBatch); //Draw the things FNA handles for us underneath the hood: base.Draw(gameTime); }