<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: David Caplette</title>
    <description>The latest articles on Forem by David Caplette (@david_caplette).</description>
    <link>https://forem.com/david_caplette</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3611288%2F46f965d6-e406-4964-8ef2-c82b890d3a55.jpg</url>
      <title>Forem: David Caplette</title>
      <link>https://forem.com/david_caplette</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/david_caplette"/>
    <language>en</language>
    <item>
      <title>Drawing and Writing in MonoGame</title>
      <dc:creator>David Caplette</dc:creator>
      <pubDate>Thu, 27 Nov 2025 19:34:28 +0000</pubDate>
      <link>https://forem.com/david_caplette/drawing-and-writing-in-monogame-10m9</link>
      <guid>https://forem.com/david_caplette/drawing-and-writing-in-monogame-10m9</guid>
      <description>&lt;p&gt;After learning how the skeleton of a MonoGame application works, we should be ready to learn the basics of how we can Draw images and Write text in the Game window.&lt;/p&gt;

&lt;h2&gt;
  
  
  Image
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1gl9742o4szjoam17g6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fq1gl9742o4szjoam17g6.png" alt="Example Texture" width="256" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To be able to draw an image, first you need an image, or what we will call a texture. You can download the image below to be able to follow and try on your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Editor
&lt;/h2&gt;

&lt;p&gt;Second you need to locate what is called the MGCB editor and open it. In Visual Studio 2022 it's located here in the Solution Explorer... just double click it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9onpuhcdh5ni4768godj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9onpuhcdh5ni4768godj.png" alt="Where is the MCGB Editor in Visual Studio 2022" width="313" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you use Visual Studio Code it will be somewhere at the top of your window when you use the MonoGame for VSCode extension.&lt;/p&gt;

&lt;p&gt;You can also use the Command Prompt by going to your project folder and typing...&lt;/p&gt;

&lt;p&gt;&lt;code&gt;dotnet mgcb-editor ./Content/Content.mgcb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When opened, the MCGB Editor will look like this...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkc8aez0vbn7kwpm80s2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgkc8aez0vbn7kwpm80s2.png" alt="The Editor Window" width="800" height="490"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can write click on Content -&amp;gt; Add -&amp;gt; Existing Item... and locate the Texture file you saved. Select -&amp;gt; Copy the file to the directory and click Add.&lt;/p&gt;

&lt;p&gt;I suggest to organize your resources in folders in the Editor, but for now it's ok like this.&lt;/p&gt;

&lt;p&gt;While we are here, we will also create the SpriteFont file that we will need to write text to the screen.&lt;/p&gt;

&lt;p&gt;Again, right click on Content -&amp;gt; Add -&amp;gt; New Item... type the name "OurFont" and select SpriteFont Description, the click on Create.&lt;/p&gt;

&lt;p&gt;Now at the top of the editor, locate the Rebuild button, press it... and then Save. You will notice that your files are now in the Content folder in your project. These files will be built as binary files that will be usable on different platforms, so it makes our lives easier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Drawing an image
&lt;/h2&gt;

&lt;p&gt;Now let's go to the Game1.cs file.&lt;br&gt;
We will need to have a variable to put our image into. So let's add this variable at the top of the class with other variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private Texture2D _ourTexture;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the LoadContent method, let's load the texture like this. The string should be the name of your texture file without the extension.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_ourTexture = Content.Load&amp;lt;Texture2D&amp;gt;("test");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then in the Draw method, after GraphicsDevice.Clear, add this. We will not see what the different parameters are doing for now, but the first one is your Texture variable and the second one a Vector of the position on the screen... you can play with it and see what it does.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_spriteBatch.Begin();

_spriteBatch.Draw(_ourTexture, Vector2.Zero, Color.White);

_spriteBatch.End();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you want to draw things to the screen you need to use the Begin function of the SpriteBatch, draw what you want and then call the End function. You should batch as many Draw calls as possible to optimize the use of the Graphics Card.&lt;/p&gt;

&lt;p&gt;If you start the application, you should see something like this.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4cqs8fnwv96kzrgdhof.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl4cqs8fnwv96kzrgdhof.png" alt="Application Test 1" width="800" height="516"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now let's do something similar to be able to write text.&lt;br&gt;
You can open the OurFont.spritefont to edit the different parameters there... I will change the Size to 48. &lt;br&gt;
Also you need to make sure that the platform you target will support the FontName that you choose.&lt;/p&gt;
&lt;h2&gt;
  
  
  Drawing Text
&lt;/h2&gt;

&lt;p&gt;Let's go a bit faster now... at the top of the class in the variables, add this to save our font.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private SpriteFont _ourFont;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then in LoadContent, we need to load the font.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_ourFont = Content.Load&amp;lt;SpriteFont&amp;gt;("OurFont");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And in the Draw method after our Texture draw, but before the _spriteBatch.End() calss, let's add this. We will more the text to the position 300,100 on the screen and choose a nice color.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;_spriteBatch.DrawString(_ourFont, "Our Font!", new Vector2(300, 100), Color.MonoGameOrange);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you did everything correctly, it should now look like this when you start the application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a0xba2cxwyec2pl5ak9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2a0xba2cxwyec2pl5ak9.png" alt="Application Test 2" width="800" height="517"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I now suggest to play with what we did so far to familiarize yourself with the different parameters when drawing a texture or a font.&lt;br&gt;
We will then start to make something a bit more complicated in the next article and learn how to use images in a different way with all the parameters.&lt;/p&gt;

&lt;p&gt;Feel free to comment, ask questions, or correct me... we are all here to learn :)&lt;/p&gt;

&lt;p&gt;See you&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;David&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>monogame</category>
      <category>csharp</category>
      <category>gamedev</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Hello MonoGame</title>
      <dc:creator>David Caplette</dc:creator>
      <pubDate>Fri, 14 Nov 2025 17:41:13 +0000</pubDate>
      <link>https://forem.com/david_caplette/hello-monogame-4ial</link>
      <guid>https://forem.com/david_caplette/hello-monogame-4ial</guid>
      <description>&lt;p&gt;This is my first post, I don't know exactly where this will lead, but my idea is to share some of my MonoGame and C# knowledge while I'm developing a small game using these pieces of technology. I'm planning to keep these posts as short as possible, but let's see how that goes.&lt;/p&gt;

&lt;p&gt;First things first... and I know it was described by many people already, but it will be a practice in writing for me as well as maybe new information for someone who stumble on my post before the post of someone else.&lt;/p&gt;

&lt;p&gt;I will skip the what are .Net, C# and MonoGame and how to setup your machine to use them as it depends on your environment, so here we go.&lt;/p&gt;

&lt;p&gt;When using the MonoGame Cross-Platform template, you will get a class called Game1. Let's go through it to understand the very basic skeleton of a MonoGame application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Variables
&lt;/h2&gt;

&lt;p&gt;First you will get these two variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I can say very simply, the GraphicsDeviceManager will interact with your GPU (Graphics Card) and the SpriteBatch will be used to render 2D graphics and text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Constructor
&lt;/h2&gt;

&lt;p&gt;Then we get the constructor where the GraphicsDeviceManager is initialized and the ContentManager get a directory where the content (images, fonts, audio...) will be loaded later. Other things might happen there in the future.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public Game1()
{
    _graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
    IsMouseVisible = true;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Initialize
&lt;/h2&gt;

&lt;p&gt;After the constructor, the Initialize function is called. Here the base.Initialize() call should not be deleted, it's important for some platform specific initializations. But you can add game specific initializations that need to run once at the start.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void Initialize()
{
    base.Initialize();
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  LoadContent
&lt;/h2&gt;

&lt;p&gt;At the end of base.Initialize, the LoadContent method is called, this timing might be important to remember for dependencies of what you want to initialize or load. Here is a good place to load game content, like images, audio, fonts...&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void LoadContent()
{
    _spriteBatch = new SpriteBatch(GraphicsDevice);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The Game Loop
&lt;/h2&gt;

&lt;p&gt;Now we arrive in what is called the game loop. Basically the whole time your game is running, both the Update and Draw functions are called one after the other. If you don't change anything, MonoGame will try to execute these functions 60 times per second... at least that's the goal.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update
&lt;/h2&gt;

&lt;p&gt;In the Update function, not much is happening, but later this would be the place to check for inputs, update the position of content in your game, check for collisions... etc.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void Update(GameTime gameTime)
{
    if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
        Exit();

    base.Update(gameTime);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Draw
&lt;/h2&gt;

&lt;p&gt;The Draw method is also not doing much for now, but it's clearing the screen so that it is ready to draw something new on the screen.&lt;br&gt;
You should avoid putting code here that updates important things, because, as far as I know, if your game is running too slow, MonoGame will prioritize Update and might not call Draw as often, so it might cause some weird things.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);

    base.Draw(gameTime);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Now that you know a bit about the skeleton of a MonoGame application, we can draw our first things on the screen in the next post.&lt;/p&gt;

&lt;p&gt;Feel free to comment, ask questions, or correct me... we are all here to learn :)&lt;/p&gt;

&lt;p&gt;See you&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;David&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>monogame</category>
      <category>csharp</category>
      <category>gamedev</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
