Repository
What Will I Learn?
- You will learn what is FNA and XNA.
- You will learn to make basic settings to make the game code.
- You will learn the basic methods for FNA-XNA.
Requirements
- Basic C# knowledge
- Visual Studio Github
Difficulty
- Basic
Tutorial Contents
I'm starting the FNA-XNA Game Programming article series with this article.
What is XNA first? I want to talk a little bit about this.
XNA is a Microsoft-developed framework for developing 2D and 3D games in a .Net environment. XNA is not a programming language or technique, it is a framework consisting of hundreds of classes.
Instead of dealing with the low-level functions of DirectX or OpenGL, the programmer is coded to provide more manageable, usable, OOP classes.
As such, it is a good starting point for those who want to start developing games.
I can talk about the fna according to what I talk about xna.
FNA is rearranged of XNA framework.
Game can be programmed as open source for all platforms with FNA.
Let's start programming games by loading FNA.
FNA Load Operations
To use the FNA frameworks, we first need to download the necessary files from here
After downloading the files, we open the file named FNA.sln in visual studio.
After opening visual studio, bring the project to Release mode and build it.
So the FNA.dll file was created in the Release folder under the bin folder.
Create Project
Open the visual studio and create a new project.
Select Windows Classic Desktop from the pop-up window and choose Empty Project.
First Step
Second Step
After opening the project, we need to add the FNA.dll file to the References section so that we can use the code in the library.
Now we can create our game Project
Create Program Codes
When we run the XNA Game, the static void Main () method of the Program class in Program.cs is executed as the starting point.
So we have to right click on the project and select Add >> Class.
Set the name of the class to Program.cs.
The work done by the Main() method is simple;
Create an instance from Game1 class and call the Run() method.
static void Main(string[] args)
{
using (Game1 game = new Game1())
{
game.Run();
}
}
In order to get instance from Game1 class, Game1 class has to be created.
Let's add a new class to the project and set it name Game1.
Let's set the contents of the Game1 class as follows.
public class Game1:Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
base.Draw(gameTime);
}
}
Some classes will not be seen here. This is why namespaces are not included in the class.
Let's include the following namespaces in the project.
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
I will explain the methods in the class and run the project.
LoadContent (): We will use the method in the charts - sounds - etc. It is the place we have installed in memory.
Update (): method, objects to be drawn on screen, position-height-transparency-etc. where the values are calculated.
Draw (): method is where objects are drawn to the screen.
The .Net Framework aims to draw 60 frames at a fixed rate. We need to wait for the Update () and Draw () methods to run at 60 seconds.
Running Project
Some settings need to be made in our project so that we can run our game before running the project.
Right-click on the project to open the Properties window.
In the pop-up window, set the Target Framework and Output type as follows.
Application tab
FNA uses a libraries sounds, images, and input / output. You can access these libraries from here.
Let's copy this library file in the folder where your game project is.
Let's open the Build Event tab of the Properties window and write the following code in the Post-build event command line section.
xcopy /y /d "$(ProjectDir)fnalibs\x64\*.dll" "$(ProjectDir)$(OutDir)"
We can now run our project.
The game screen opens when my project is run. The reason for opening the game area in blue is that the Color.CornflowerBlue command is used in the Draw() method.
We can create games using FNA-XNA after we have done these settings.