Skip to content

AvaloniaInside/AvaloniaInside.MonoGame

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AvaloniaInside.MonoGame

NuGet NuGet Downloads License: MIT

AvaloniaInside.MonoGame enables seamless integration of MonoGame content within Avalonia UI applications. Embed MonoGame games and graphics directly into your cross-platform Avalonia controls.

โœจ Features

  • ๐ŸŽฎ Easy Integration - Add MonoGame content to Avalonia apps with just a control
  • ๐Ÿ–ผ๏ธ Control-Based - Use MonoGame as a standard Avalonia XAML control
  • ๐ŸŽฏ Resolution Rendering - Built-in ResolutionRenderer for resolution-independent rendering
  • ๐Ÿ”„ Cross-Platform - Works on Desktop platforms (Windows, macOS, Linux)
  • โšก Simple API - Minimal setup required to get started

๐Ÿ“ฆ Installation

Install the package to your project using the command below or visit the NuGet package page for other installation methods.

dotnet add package AvaloniaInside.MonoGame

Or via Package Manager Console:

Install-Package AvaloniaInside.MonoGame

๐Ÿ“‹ Requirements

  • .NET 8.0 or .NET 10.0
  • Avalonia 11.3.9 or higher
  • MonoGame.Framework.DesktopGL 3.8.4.1 or higher

๐Ÿš€ Quick Start

1. Create Your MonoGame Class

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

public class MyExampleGame : Game
{
    private GraphicsDeviceManager _graphics;
    private SpriteBatch _spriteBatch;

    public MyExampleGame()
    {
        _graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    protected override void LoadContent()
    {
        _spriteBatch = new SpriteBatch(GraphicsDevice);
    }

    protected override void Update(GameTime gameTime)
    {
        // Your game logic here
        base.Update(gameTime);
    }

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

        // Your drawing code here

        base.Draw(gameTime);
    }
}

2. Add the Namespace to Your Avalonia View

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:monoGame="clr-namespace:AvaloniaInside.MonoGame;assembly=AvaloniaInside.MonoGame"
             x:Class="YourNamespace.YourView">

    <monoGame:MonoGameControl Game="{Binding CurrentGame}" />

</UserControl>

3. Set Up Your ViewModel

public class MainViewModel : ViewModelBase
{
    public Game CurrentGame { get; set; } = new MyExampleGame();
}

MonoGame running in Avalonia

๐Ÿ“š Examples

Check out the example project in this repository for comprehensive usage examples including:

  • Basic MonoGame integration
  • Auto-playing Pong game
  • Input handling patterns
  • Content loading and management

๐Ÿ”ง Advanced Usage

Resolution-Independent Rendering

Use the ResolutionRenderer class for resolution-independent rendering:

public class MyGame : Game
{
    private ResolutionRenderer _resolutionRenderer;

    protected override void Initialize()
    {
        _resolutionRenderer = new ResolutionRenderer(
            this,
            new Point(1920, 1080), // Virtual resolution
            new Point(1920, 1080)  // Actual resolution
        );

        base.Initialize();
    }

    protected override void Draw(GameTime gameTime)
    {
        _resolutionRenderer.BeginDraw();

        // Your drawing code here

        base.Draw(gameTime);
    }
}

โš ๏ธ Known Issues

  1. Mobile platforms - Not currently supported (iOS, Android)
  2. Input handling - Device input should be managed through native Avalonia input system rather than MonoGame's input
  3. Performance - Performance optimizations are ongoing; may not be optimal for all scenarios yet

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ”— Links


Made with โค๏ธ by the AvaloniaInside team

About

Integration of MonoGame for Avalonia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages