kandi background
Explore Kits

MonoGame | One framework for creating powerful crossplatform games. | Game Engine library

 by   MonoGame C# Version: v3.8 License: Non-SPDX

 by   MonoGame C# Version: v3.8 License: Non-SPDX

Download this library from

kandi X-RAY | MonoGame Summary

MonoGame is a C# library typically used in Telecommunications, Media, Media, Entertainment, Gaming, Game Engine, Framework applications. MonoGame has no bugs, it has no vulnerabilities and it has medium support. However MonoGame has a Non-SPDX License. You can download it from GitHub.
One framework for creating powerful cross-platform games. The spiritual successor to XNA with thousands of titles shipped across desktop, mobile, and console platforms. MonoGame is a fully managed .NET open source game framework without any black boxes. Create, develop and distribute your games your way.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • MonoGame has a medium active ecosystem.
  • It has 7658 star(s) with 2492 fork(s). There are 500 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 656 open issues and 2673 have been closed. On average issues are closed in 552 days. There are 83 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of MonoGame is v3.8
MonoGame Support
Best in #Game Engine
Average in #Game Engine
MonoGame Support
Best in #Game Engine
Average in #Game Engine

quality kandi Quality

  • MonoGame has 0 bugs and 0 code smells.
MonoGame Quality
Best in #Game Engine
Average in #Game Engine
MonoGame Quality
Best in #Game Engine
Average in #Game Engine

securitySecurity

  • MonoGame has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • MonoGame code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
MonoGame Security
Best in #Game Engine
Average in #Game Engine
MonoGame Security
Best in #Game Engine
Average in #Game Engine

license License

  • MonoGame has a Non-SPDX License.
  • Non-SPDX licenses can be open source with a non SPDX compliant license, or non open source licenses, and you need to review them closely before use.
MonoGame License
Best in #Game Engine
Average in #Game Engine
MonoGame License
Best in #Game Engine
Average in #Game Engine

buildReuse

  • MonoGame releases are available to install and integrate.
  • Installation instructions are available. Examples and code snippets are not available.
  • MonoGame saves you 825 person hours of effort in developing the same functionality from scratch.
  • It has 1893 lines of code, 0 functions and 1311 files.
  • It has low code complexity. Code complexity directly impacts maintainability of the code.
MonoGame Reuse
Best in #Game Engine
Average in #Game Engine
MonoGame Reuse
Best in #Game Engine
Average in #Game Engine
Top functions reviewed by kandi - BETA

Coming Soon for all Libraries!

Currently covering the most popular Java, JavaScript and Python libraries. See a SAMPLE HERE.
kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.

MonoGame Key Features

Build Status

Supported Platforms

Support and Contributions

Source Code

Helpful Links

License

Monogame-uwp package can´t be published to the Windows Store because it still targets Windows.Mobile and can´t be enrypted because of that

copy iconCopydownload iconDownload
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.10049.0" MaxVersionTested="10.0.10049.0" />

How to draw on the fly 2D pixel-by-pixel in MonoGame/XNA?

copy iconCopydownload iconDownload
Texture2D pixel = new Texture2D(GraphicsDevice, 1, 1);
pixel.SetData(new Color[] {Color.White});
-----------------------
Texture2D Tex, Tex1, Tex2;
const int WIDTH = 32;
const int HEIGHT = 32;
Color[] TexSource = new Color[WIDTH * HEIGHT];
int radius = 5;
point center = new Point(WIDTH >> 2, HEIGHT >> 2);
Tex = new Texture2D(GraphicsDevice, WIDTH, HEIGHT);
for(int x = 0 ; x < WIDTH; x++)
  for(int y = 0 ; y < HEIGHT; y++)
    if(Math.Sqrt((x - center.x)* (x - center.x)) < radius && Math.Sqrt((y - center.y) * (y - center.y) < radius))
       TexSource[x + y * WIDTH] = Color.Red;
    else
       TexSource[x + y * WIDTH] = Color.White;
  Tex = SetData<Color>(TexSource);    
  //The resulting texture is a red circle on a white background.

  //If you want to draw on top of an existing texture Tex1 as Tex2:
  Tex1 = Content.Load<Texture2D>(Tex1Name);
  Tex2 = new Texture2D(GraphicsDevice, Tex1.Width, Tex1.Height);
  TexSource = Tex1.GetData<Color>();
  // Draw a white \ on the image, we will assume tex1 is square for this task
  for(int x = 0 ; x < Tex1.Width; x++)
    for(int y = 0 ; y < Tex1.Width; y++)
       if(x==y) TexSource[x + y * Tex1.Width] = Color.White;

-----------------------
Texture2D Tex, Tex1, Tex2;
const int WIDTH = 32;
const int HEIGHT = 32;
Color[] TexSource = new Color[WIDTH * HEIGHT];
int radius = 5;
point center = new Point(WIDTH >> 2, HEIGHT >> 2);
Tex = new Texture2D(GraphicsDevice, WIDTH, HEIGHT);
for(int x = 0 ; x < WIDTH; x++)
  for(int y = 0 ; y < HEIGHT; y++)
    if(Math.Sqrt((x - center.x)* (x - center.x)) < radius && Math.Sqrt((y - center.y) * (y - center.y) < radius))
       TexSource[x + y * WIDTH] = Color.Red;
    else
       TexSource[x + y * WIDTH] = Color.White;
  Tex = SetData<Color>(TexSource);    
  //The resulting texture is a red circle on a white background.

  //If you want to draw on top of an existing texture Tex1 as Tex2:
  Tex1 = Content.Load<Texture2D>(Tex1Name);
  Tex2 = new Texture2D(GraphicsDevice, Tex1.Width, Tex1.Height);
  TexSource = Tex1.GetData<Color>();
  // Draw a white \ on the image, we will assume tex1 is square for this task
  for(int x = 0 ; x < Tex1.Width; x++)
    for(int y = 0 ; y < Tex1.Width; y++)
       if(x==y) TexSource[x + y * Tex1.Width] = Color.White;

Where did these borders come from in Monogame Android?

copy iconCopydownload iconDownload
#if ANDROID
            graphics.IsFullScreen = true;                
            graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            graphics.SupportedOrientations = DisplayOrientation.Portrait;//if your game does NOT support for anything else but portrait mode
            graphics.ApplyChanges();
#endif

C# cannot convert from 'float' to 'Microsoft.Xna.Framework.Point'

copy iconCopydownload iconDownload
int scaledSize = (int)(sizeOfSprites * scale);
Microsoft.Xna.Framework.Rectangle position = new Microsoft.Xna.Framework.Rectangle(
  cell.X * scaledSize,
  cell.Y * scaledSize,
  scaledSize,
  scaledSize
);
-----------------------
Microsoft.Xna.Framework.Rectangle position = new Microsoft.Xna.Framework.Rectangle(
  (int)(cell.X * SIZE),  (int)(cell.Y * SIZE),  SIZE, SIZE);
);

My ball and my rectangle wont collide properly (Monogame)

copy iconCopydownload iconDownload
public void enemyCollision(Rectangle enemyRectangle)
{
    if (ballRectangle.Intersects(enemyRectangle))
        ballDirectionY = false;
}
public void enemyCollision(Rectangle enemyRectangle)
{
    if (ballRectangle.Intersects(enemyRectangle))
    {
        if (ballRectangle.x > enemyRectangle.x && 
            ballRectangle.x < enemyRectangle.x + enemyRectangle.Width && 
            ballRectangle.y > enemyRectangle.y)
             ballDirectionY = false;
    }
}
-----------------------
public void enemyCollision(Rectangle enemyRectangle)
{
    if (ballRectangle.Intersects(enemyRectangle))
        ballDirectionY = false;
}
public void enemyCollision(Rectangle enemyRectangle)
{
    if (ballRectangle.Intersects(enemyRectangle))
    {
        if (ballRectangle.x > enemyRectangle.x && 
            ballRectangle.x < enemyRectangle.x + enemyRectangle.Width && 
            ballRectangle.y > enemyRectangle.y)
             ballDirectionY = false;
    }
}

Monogame not drawing png images

copy iconCopydownload iconDownload
protected override void LoadContent()
        {
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            
            realisticSturgeonSprite = Texture2D.FromFile(GraphicsDevice,@"Lake_Sturgeon.png"); 
  // you can add path if needed (copy to output option above doesn't need it)
        }


        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            _spriteBatch.Begin();

            _spriteBatch.Draw(realisticSturgeonSprite, new Vector2(50, 60), Color.White);

            _spriteBatch.End();
           

            base.Draw(gameTime);
        }

Monogame buttons

copy iconCopydownload iconDownload
_spriteBatch.Draw(ButtonTexture,ButtonRectangle,Color.White);
ButtonRectangle = new Rectangle(ScreenX * 0.4,ScreenY*0.5,ScreenX * 0.1,ScreenY*0.1);
MouseState mouse = Mouse.GetState();
if(ButtonRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed)
{
//do stuff
}
-----------------------
_spriteBatch.Draw(ButtonTexture,ButtonRectangle,Color.White);
ButtonRectangle = new Rectangle(ScreenX * 0.4,ScreenY*0.5,ScreenX * 0.1,ScreenY*0.1);
MouseState mouse = Mouse.GetState();
if(ButtonRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed)
{
//do stuff
}
-----------------------
_spriteBatch.Draw(ButtonTexture,ButtonRectangle,Color.White);
ButtonRectangle = new Rectangle(ScreenX * 0.4,ScreenY*0.5,ScreenX * 0.1,ScreenY*0.1);
MouseState mouse = Mouse.GetState();
if(ButtonRectangle.Contains(mouse.Position) && mouse.LeftButton == ButtonState.Pressed)
{
//do stuff
}

c# monogame gradually rotate camera behind a player

copy iconCopydownload iconDownload
float newRotation = targetY;

if (targetY < MathHelper.ToRadians(90) && currentY > MathHelper.ToRadians(270))
{
    newRotation = targetY + MathHelper.ToRadians(360);
}
if (targetY > MathHelper.ToRadians(270) && currentY < MathHelper.ToRadians(90))
{
    newRotation = targetY - MathHelper.ToRadians(360);
}
if (currentY < newRotation)
{
    currentY += (newRotation - currentY) / rotateSpeed;
}
if (currentY > newRotation)
{
    currentY -= Math.Abs(newRotation - currentY) / rotateSpeed;
}
if (currentY >= MathHelper.Pi * 2) currentY = 0.0f;
if (currentY < 0) currentY = MathHelper.Pi * 2;
-----------------------
float newRotation = targetY;

if (targetY < MathHelper.ToRadians(90) && currentY > MathHelper.ToRadians(270))
{
    newRotation = targetY + MathHelper.ToRadians(360);
}
if (targetY > MathHelper.ToRadians(270) && currentY < MathHelper.ToRadians(90))
{
    newRotation = targetY - MathHelper.ToRadians(360);
}
if (currentY < newRotation)
{
    currentY += (newRotation - currentY) / rotateSpeed;
}
if (currentY > newRotation)
{
    currentY -= Math.Abs(newRotation - currentY) / rotateSpeed;
}
if (currentY >= MathHelper.Pi * 2) currentY = 0.0f;
if (currentY < 0) currentY = MathHelper.Pi * 2;

Monogame VsCode extension isn't working properly when I try to use it

copy iconCopydownload iconDownload
dotnet tool install --global dotnet-mgcb-editor
mgcb-editor --register
"mgcb.pipelineToolPath": "mgcb-editor"
-----------------------
dotnet tool install --global dotnet-mgcb-editor
mgcb-editor --register
"mgcb.pipelineToolPath": "mgcb-editor"

Physics Simulation Ball falling into floor

copy iconCopydownload iconDownload
if (particle.Top < 0)
{
    velocity.Y = -velocity.Y;
    particle.Y = -particle.Y;
}
else if (particle.Bottom >= GraphicsDevice.ViewPort.Height)
{
    velocity.Y = -velocity.Y;
    particle.Y = GraphicsDevice.ViewPort.Height - (particle.Bottom - GraphicsDevice.ViewPort.Height + particle.Height);
}

Community Discussions

Trending Discussions on MonoGame
  • How to structure a project in Monogame
  • Monogame Content not building from VS
  • Monogame-uwp package can&#180;t be published to the Windows Store because it still targets Windows.Mobile and can&#180;t be enrypted because of that
  • How to draw on the fly 2D pixel-by-pixel in MonoGame/XNA?
  • Where did these borders come from in Monogame Android?
  • C# cannot convert from 'float' to 'Microsoft.Xna.Framework.Point'
  • My ball and my rectangle wont collide properly (Monogame)
  • Monogame not drawing png images
  • Monogame buttons
  • c# monogame gradually rotate camera behind a player
Trending Discussions on MonoGame

QUESTION

How to structure a project in Monogame

Asked 2022-Mar-14 at 17:18

I'm trying to create a PC version of a cord-driven turn-based boardgame. I went for the Monogame framework in c#. I'm still learning C# and Monogame and I'm reading all about how it is important to "split" the code in the data/game engine part and the graphics/GUI part. So trying to pursue this, I have the following in mind.

Graphics/GUI

Here I define all the classes relative to the screens (game - menus), GUI components like labels and buttons and possibly even mouse and keyboard inputs (the logic being the user has to click on something in the gui in order to perform an action).

Data or Game logic/Engine

Still not even sure on how I should call this part of the project, here I would put all the logic of the game. The classes of player, cards, "IA", rules etc... would be defined here.

My difficulty is now to understand how to connect this two parts but still maintain the "loosely coupled" approach. I was thinking that maybe the objects or better the instances of the game logic part would have to subscribe to events (such as button_click) defined in the GUI part...but can I even subscribe to events of another class? Is this the correct way?

I admit I'm still trying to fully understand the event driven concept, but is this the right way of doing stuff in c# and Monogame? I apologize for the vague topic/question but thanks in advance.

ANSWER

Answered 2022-Mar-14 at 17:18

I don't know anything about Monogame, but generally it's a good idea to organise any kind of application into layers like this, as long as you don't make the code overly complicated by doing so. Your idea to separate the UI code from the game logic sounds like a good start.

First, think of your application as an onion, with a series of concentric layers. Your proposed structure has only two layers, but that's OK. A larger application may benefit from more layers, e.g. a data access layer if you were to store the state of the game in a database, but there's no need to add extra layers just for the sake of having more layers.

Your outermost layer would contain the UI code, typically this is known as the presentation layer.

Your innermost layer would contain the game logic, typically this is known as the domain layer. A good rule of thumb for whether something belongs in the domain layer is to ask, does this represent something that a user of your application (or a player of your game) who's not a developer would recognise?

Second, remember that each layer can make calls to code in the same layer, or to code in in other layers inside it, but not to code in layers outside it. So projects in the presentation layer can have references to projects in the domain layer, but projects in the domain layer can't have references to projects in the presentation layer. If you've got circular references between the two layers then it's a sign that something in one of the layers actually belongs in the other layer.

Here's another answer to a similar question about layering an application, albeit not in the context of a game: https://stackoverflow.com/a/70315655/16563198

On the second part of the question, if you want to use events then it's probably best to handle any events in the presentation layer and have the event handlers make calls into the domain layer (but disclaimer, I don't know Monogame).

Source https://stackoverflow.com/questions/71469599

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install MonoGame

Our build server builds, tests, and packages the latest MonoGame changes. The table below shows the current build status for the develop branch.

Support

We support a growing list of platforms across the desktop, mobile, and console space. If there is a platform we don't support, please make a request or come help us add it.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Reuse Pre-built Kits with MonoGame
Compare Game Engine Libraries with Highest Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.