Game Programming with FNA-XNA

in utopian-io •  6 years ago 

1200px-Microsoft_XNA_logo.svg.png

Repository

FNA-XNA Github

Visual Studio Github

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

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.

FNA0.JPG

After opening visual studio, bring the project to Release mode and build it.

FNA1.JPG

So the FNA.dll file was created in the Release folder under the bin folder.

FNA2.JPG

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
FNA3.JPG

Second Step
FNA4.JPG

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.

FNA5.JPG

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
FNA6.JPG

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)"



FNA8.JPG


We can now run our project.
FNA9.JPG


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.

Proof of Work Done

https://github.com/FNA-XNA/FNA

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

The code of your contribution has been found to be plagiarized from the following source here. Plagiarism is a serious offense.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @portugalcoin!

So far this week you've reviewed 9 contributions. Keep up the good work!

Your account has been banned from receiving future Utopian reviews due to plagiarism.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Congratulations @zello! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!