Getting Started with
MonoGame using 2D
DARKSIDE OF MONOGAME
SIMON JACKSON
AUTHOR AND MICROSOFT MVP
@SIMONDARKSIDEJ
What this tutorial covers
• Basic Concepts
• Game Loop
• Content
• Your First 2D project
• Build Content Project
• Create Project
• Add code and assets
• The Bigger Picture
• Project Structure
• State Management
• Tips ‘N’Tricks
*Doesn’t include instructions on HOW to code :D
Check the original 2D starter course I did for that
http://bit.ly/2mT2pQd
Or check out Rob Miles’s “LittleYellow Book”
http://www.csharpcourse.com/
Update
Loop
Content
&
Drawing
Handling
Input
Audio
Basic 2D / Game Development
concepts
WHAT MAKES A GAME?
Simple Concepts
• Game - XNA Game definition
• Graphics Device - The Graphics card definition
• Sprite Batch - 2D Batch drawing call
• Content Manager - The Content Pipeline
• Vectors / Rectangles /Textures - MonoGame structures
• Game Loop - The loop the game
• Initialize (while running) goes through to deliver
• Update your game
• Draw
The Game Loop
• Set Initial State
• Load Content
Initialize
• Handle Input
• Apply Physics
• Set Position
Update • Draw
Background
• Draw Foreground
• Apply Shaders
Draw
2D Drawing
JUST GETTING SOME STUFF ON THE SCREEN
Drawing in 2D – Order is important
When drawing a 2D game (or any other type tbh), the order in which
you draw them is very important:
• Drawing is done from back to the front
• Things drawn first begin at the back
• Additional calls draw on top of each other
• Same as if you were drawing with paint on a canvas
Coordinates
When drawing in 2D, the top-left of the screen is the start of the screen.
Or inVector terms –Vector2(0,0)
Values then increase:
• Across to the right for X
• Downwards forY
Any object drawn to the screen
follows the same pattern
X Positive ->
YPositive->
Position
Vector2(10,10)
Effects
It is also possible to apply effects to images / text as they are drawn, either:
• Individually
• A group of images
• To the entire screen
This can allow you to:
• Blend colors together
• Overwrite portions
• Anything else your mind has to dream
Input & Animation
MAKING STUFF MOVE
Input
Input is handled as a “state” between each game update loop.
MonoGame checks what the new position is for each type of input, you have
to decide what to do with that information.
In most games, you preserve the previous state of input, to determine if the
player has:
• Just pressed an input
• Just released an input
• Is holding an input
Once you know the player has done something, you decide what to do with
that information.
Animation
Animation, like the movies, is just a way to fool humans that an image
is actually moving. This is achieved in games by either:
• Moving the image across the screen between frames
• Replacing the image with a slightly different image
• A combination of both of these
MonoGame can support both:
• Individual images for animation
• Multiple images combined on a single image with multiple “frames”
of animation. Also known as Spritesheets.
Animation
SINGLE TEXTURE
SPRITE SHEET
MULTIPLE IMAGES
Frame 1 Frame 2 Frame 3
Audio
ADDING SOME SOUND
Audio
Audio comes in two forms within the MonoGame Framework:
• Sound – Fire and forget, just play and go
• Sound Instance – More control, used for music and deeper effects
• Song – Music and looping audio
Audio is loaded from the Content Manger like any other asset
Then you can either:
• Just play is as required, e.g. Fire a bullet
• Create an instance and play, loop, increase/decrease pitch, etc
Enough talk
SHOW ME THE CODE
Going further
MANAGING THE STATE OF YOUR GAME
Game State Management
Games are more than just the gameplay, to be complete you will also
need:
• Menus
• Configuration / Settings screens
• Help / info pages
• More levels?
As you only have ONE game loop, you need to enable your game to
understand the different “states” your game will be in.
This is referred to as Game State Management
Game State Management
sample
MANAGING THE STATE OF YOUR GAME EXAMPLE
Further Reading
WHERE CAN YOU LEARN MORE
More information
Many sources exist to detail more about basic 2D drawing:
• http://www.monogame.rocks/documentation
A good start but docs still aWIP
• http://www.monogame.rocks/documentation/?page=Tutorials
A selection of other MonoGame tutorials, some old but still relevant
• https://github.com/DDReaper/XNAGameStudio
Archived Microsoft XNA samples. A great “how to” selection.
Most are being converted over to MonoGame direct, like the
GameStateManagement sample
• The Darkside of MonoGame
http://www.youtube.com/c/TheDarksideofMonoGame
Either where you are watching this from or where you should go next!
Thanks for watching
DARKSIDE OF MONOGAME
SIMON JACKSON
AUTHOR AND MICROSOFT MVP
@SIMONDARKSIDEJ

Getting started with MonoGame using 2D

  • 1.
    Getting Started with MonoGameusing 2D DARKSIDE OF MONOGAME SIMON JACKSON AUTHOR AND MICROSOFT MVP @SIMONDARKSIDEJ
  • 2.
    What this tutorialcovers • Basic Concepts • Game Loop • Content • Your First 2D project • Build Content Project • Create Project • Add code and assets • The Bigger Picture • Project Structure • State Management • Tips ‘N’Tricks *Doesn’t include instructions on HOW to code :D Check the original 2D starter course I did for that http://bit.ly/2mT2pQd Or check out Rob Miles’s “LittleYellow Book” http://www.csharpcourse.com/ Update Loop Content & Drawing Handling Input Audio
  • 3.
    Basic 2D /Game Development concepts WHAT MAKES A GAME?
  • 4.
    Simple Concepts • Game- XNA Game definition • Graphics Device - The Graphics card definition • Sprite Batch - 2D Batch drawing call • Content Manager - The Content Pipeline • Vectors / Rectangles /Textures - MonoGame structures • Game Loop - The loop the game • Initialize (while running) goes through to deliver • Update your game • Draw
  • 5.
    The Game Loop •Set Initial State • Load Content Initialize • Handle Input • Apply Physics • Set Position Update • Draw Background • Draw Foreground • Apply Shaders Draw
  • 6.
    2D Drawing JUST GETTINGSOME STUFF ON THE SCREEN
  • 7.
    Drawing in 2D– Order is important When drawing a 2D game (or any other type tbh), the order in which you draw them is very important: • Drawing is done from back to the front • Things drawn first begin at the back • Additional calls draw on top of each other • Same as if you were drawing with paint on a canvas
  • 8.
    Coordinates When drawing in2D, the top-left of the screen is the start of the screen. Or inVector terms –Vector2(0,0) Values then increase: • Across to the right for X • Downwards forY Any object drawn to the screen follows the same pattern X Positive -> YPositive-> Position Vector2(10,10)
  • 9.
    Effects It is alsopossible to apply effects to images / text as they are drawn, either: • Individually • A group of images • To the entire screen This can allow you to: • Blend colors together • Overwrite portions • Anything else your mind has to dream
  • 10.
  • 11.
    Input Input is handledas a “state” between each game update loop. MonoGame checks what the new position is for each type of input, you have to decide what to do with that information. In most games, you preserve the previous state of input, to determine if the player has: • Just pressed an input • Just released an input • Is holding an input Once you know the player has done something, you decide what to do with that information.
  • 12.
    Animation Animation, like themovies, is just a way to fool humans that an image is actually moving. This is achieved in games by either: • Moving the image across the screen between frames • Replacing the image with a slightly different image • A combination of both of these MonoGame can support both: • Individual images for animation • Multiple images combined on a single image with multiple “frames” of animation. Also known as Spritesheets.
  • 13.
    Animation SINGLE TEXTURE SPRITE SHEET MULTIPLEIMAGES Frame 1 Frame 2 Frame 3
  • 14.
  • 15.
    Audio Audio comes intwo forms within the MonoGame Framework: • Sound – Fire and forget, just play and go • Sound Instance – More control, used for music and deeper effects • Song – Music and looping audio Audio is loaded from the Content Manger like any other asset Then you can either: • Just play is as required, e.g. Fire a bullet • Create an instance and play, loop, increase/decrease pitch, etc
  • 16.
  • 17.
    Going further MANAGING THESTATE OF YOUR GAME
  • 18.
    Game State Management Gamesare more than just the gameplay, to be complete you will also need: • Menus • Configuration / Settings screens • Help / info pages • More levels? As you only have ONE game loop, you need to enable your game to understand the different “states” your game will be in. This is referred to as Game State Management
  • 19.
    Game State Management sample MANAGINGTHE STATE OF YOUR GAME EXAMPLE
  • 20.
  • 21.
    More information Many sourcesexist to detail more about basic 2D drawing: • http://www.monogame.rocks/documentation A good start but docs still aWIP • http://www.monogame.rocks/documentation/?page=Tutorials A selection of other MonoGame tutorials, some old but still relevant • https://github.com/DDReaper/XNAGameStudio Archived Microsoft XNA samples. A great “how to” selection. Most are being converted over to MonoGame direct, like the GameStateManagement sample • The Darkside of MonoGame http://www.youtube.com/c/TheDarksideofMonoGame Either where you are watching this from or where you should go next!
  • 22.
    Thanks for watching DARKSIDEOF MONOGAME SIMON JACKSON AUTHOR AND MICROSOFT MVP @SIMONDARKSIDEJ