Convert Figma logo to code with AI

prime31 logoNez

Nez is a free 2D focused framework that works with MonoGame and FNA

1,772
359
1,772
45

Top Related Projects

11,280

One framework for creating powerful cross-platform games.

2,590

FNA - Accuracy-focused XNA4 reimplementation for open platforms

21,434

A simple and easy-to-use library to enjoy videogames programming

6,448

Stride Game Engine (formerly Xenko)

88,735

Godot Engine – Multi-platform 2D and 3D game engine

23,130

Desktop/Android/HTML5/iOS Java game development framework

Quick Overview

Nez is a feature-rich 2D game framework built on top of MonoGame/FNA. It provides a robust set of tools and systems for game development, including a scene/entity system, component system, rendering, physics, and various other utilities. Nez aims to streamline the game development process while offering flexibility and performance.

Pros

  • Comprehensive set of features for 2D game development
  • Built on top of MonoGame/FNA, providing cross-platform compatibility
  • Active development and community support
  • Extensive documentation and examples

Cons

  • Steeper learning curve compared to simpler game engines
  • Requires knowledge of C# and MonoGame/FNA
  • May be overkill for very small or simple game projects
  • Limited 3D support (primarily focused on 2D)

Code Examples

  1. Creating a simple scene and entity:
public class MyScene : Scene
{
    public override void Initialize()
    {
        var entity = CreateEntity("player");
        entity.AddComponent(new SpriteRenderer(Content.LoadTexture("player")));
        entity.AddComponent(new PlayerController());
    }
}
  1. Implementing a basic component:
public class PlayerController : Component, IUpdatable
{
    public float MoveSpeed = 100f;

    public void Update()
    {
        var movement = Vector2.Zero;
        if (Input.IsKeyDown(Keys.Left))
            movement.X = -1f;
        if (Input.IsKeyDown(Keys.Right))
            movement.X = 1f;

        Entity.Position += movement * MoveSpeed * Time.DeltaTime;
    }
}
  1. Using the physics system:
public class PhysicsExample : Scene
{
    public override void Initialize()
    {
        var entity = CreateEntity("physicsObject");
        entity.AddComponent(new SpriteRenderer(Content.LoadTexture("box")));
        var collider = entity.AddComponent(new BoxCollider());
        var mover = entity.AddComponent<Mover>();

        // Apply gravity
        mover.AddForce(new Vector2(0, 980f));
    }
}

Getting Started

  1. Install Nez via NuGet:

    Install-Package Nez
    
  2. Create a new MonoGame project and modify the main game class:

public class Game1 : Core
{
    protected override void Initialize()
    {
        base.Initialize();
        Scene = new MyScene();
    }
}
  1. Create your first scene:
public class MyScene : Scene
{
    public override void Initialize()
    {
        // Add entities and components here
    }
}
  1. Run your game and start building!

Competitor Comparisons

11,280

One framework for creating powerful cross-platform games.

Pros of MonoGame

  • Larger community and ecosystem, with more resources and third-party libraries available
  • Cross-platform support for a wider range of platforms, including mobile and consoles
  • More mature and stable, with a longer development history

Cons of MonoGame

  • Steeper learning curve for beginners, especially those new to game development
  • Less built-in functionality, requiring more manual implementation of common game features
  • Lower-level API, which can lead to more verbose code for simple tasks

Code Comparison

MonoGame:

protected override void Draw(GameTime gameTime)
{
    GraphicsDevice.Clear(Color.CornflowerBlue);
    spriteBatch.Begin();
    spriteBatch.Draw(texture, position, Color.White);
    spriteBatch.End();
    base.Draw(gameTime);
}

Nez:

public override void render(Graphics graphics, float deltaTime)
{
    graphics.batcher.begin();
    graphics.batcher.draw(texture, position);
    graphics.batcher.end();
}

Nez provides a more streamlined API for common game development tasks, while MonoGame offers greater flexibility and control at the cost of more verbose code. MonoGame's larger ecosystem and cross-platform support make it suitable for a wider range of projects, while Nez's built-in features and simpler API can accelerate development for certain types of games.

2,590

FNA - Accuracy-focused XNA4 reimplementation for open platforms

Pros of FNA

  • More mature and established project with a longer history
  • Closer to the original XNA framework, making it easier for XNA developers to transition
  • Broader platform support, including mobile and console targets

Cons of FNA

  • Steeper learning curve for developers new to XNA-style frameworks
  • Less built-in features compared to Nez, requiring more manual implementation
  • Potentially more complex setup process for new projects

Code Comparison

Nez example:

public class MyScene : Scene
{
    public override void Initialize()
    {
        AddEntity(new Player());
    }
}

FNA example:

public class MyGame : Game
{
    protected override void Initialize()
    {
        base.Initialize();
        // Add game objects and initialization logic here
    }
}

Summary

FNA aims to be a faithful reimplementation of XNA, providing a familiar environment for XNA developers and broad platform support. Nez, built on top of FNA/MonoGame, offers a more feature-rich and beginner-friendly framework with additional tools and systems out of the box. The choice between the two depends on the developer's background, project requirements, and desired level of abstraction.

21,434

A simple and easy-to-use library to enjoy videogames programming

Pros of raylib

  • Cross-platform support for multiple programming languages (C, C++, Lua, Python, etc.)
  • Lightweight and easy to integrate into existing projects
  • Extensive documentation and examples

Cons of raylib

  • Less focused on game development specifics compared to Nez
  • Fewer high-level game-oriented features out of the box
  • Steeper learning curve for beginners in game development

Code Comparison

Nez (C#):

public class MyScene : Scene
{
    public override void Initialize()
    {
        AddEntity(new Entity().AddComponent(new SpriteRenderer(Content.LoadTexture("sprite.png"))));
    }
}

raylib (C):

#include "raylib.h"

int main(void)
{
    InitWindow(800, 450, "raylib example");
    Texture2D texture = LoadTexture("sprite.png");
    while (!WindowShouldClose())
    {
        BeginDrawing();
        DrawTexture(texture, 0, 0, WHITE);
        EndDrawing();
    }
    CloseWindow();
    return 0;
}
6,448

Stride Game Engine (formerly Xenko)

Pros of Stride

  • More comprehensive 3D game engine with advanced graphics capabilities
  • Larger community and more active development
  • Cross-platform support for multiple devices and operating systems

Cons of Stride

  • Steeper learning curve due to its complexity
  • Heavier resource requirements for development and runtime
  • Less suitable for simple 2D games compared to Nez

Code Comparison

Stride (C#):

public class MyScript : SyncScript
{
    public override void Start()
    {
        // Initialization code
    }

    public override void Update()
    {
        // Update logic
    }
}

Nez (C#):

public class MyComponent : Component, IUpdatable
{
    public override void OnAddedToEntity()
    {
        // Initialization code
    }

    public void Update()
    {
        // Update logic
    }
}

Both frameworks use C# and have similar component-based architectures. However, Stride's scripting system is more tightly integrated with its engine structure, while Nez offers a more lightweight approach that's closer to MonoGame's style.

Stride is better suited for complex 3D games with high-end graphics, while Nez excels in 2D game development and offers a simpler, more accessible framework for indie developers and smaller projects.

88,735

Godot Engine – Multi-platform 2D and 3D game engine

Pros of Godot

  • Complete game engine with built-in editor, offering a more comprehensive development environment
  • Larger community and ecosystem, providing more resources, plugins, and support
  • Multi-platform support, including web and mobile, out of the box

Cons of Godot

  • Steeper learning curve due to its custom scripting language (GDScript) and more complex architecture
  • Potentially slower performance for certain 2D scenarios compared to Nez's optimized 2D-focused approach

Code Comparison

Godot (GDScript):

extends Sprite

func _ready():
    position = Vector2(100, 100)
    scale = Vector2(2, 2)

Nez (C#):

public class Player : Entity
{
    public override void OnAddedToScene()
    {
        Position = new Vector2(100, 100);
        Scale = new Vector2(2, 2);
    }
}

Both examples demonstrate setting position and scale for a game object, showcasing the syntax differences between GDScript and C#. Godot uses a more Python-like syntax, while Nez leverages C# for its implementation.

23,130

Desktop/Android/HTML5/iOS Java game development framework

Pros of libGDX

  • Cross-platform development (desktop, mobile, web)
  • Large, active community with extensive documentation
  • Rich ecosystem of extensions and tools

Cons of libGDX

  • Steeper learning curve for beginners
  • Less streamlined for 2D game development compared to Nez
  • Requires more boilerplate code for simple projects

Code Comparison

libGDX: Creating a basic game screen

public class GameScreen implements Screen {
    @Override
    public void render(float delta) {
        // Game logic and rendering
    }
    // Other Screen methods...
}

Nez: Creating a basic scene

public class GameScene : Scene
{
    public override void Update()
    {
        // Game logic
    }
}

Summary

libGDX is a versatile, cross-platform framework with a large community and extensive features. It's well-suited for both 2D and 3D game development across multiple platforms. However, it may have a steeper learning curve and require more setup compared to Nez.

Nez, on the other hand, is more focused on 2D game development and offers a simpler, more streamlined approach for C# developers. It integrates well with MonoGame and provides a more opinionated structure, which can be beneficial for rapid development of 2D games.

The choice between the two depends on factors such as target platforms, development language preference, and the specific requirements of your game project.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Nez

Build status NuGet version NuGet downloads Join the chat Website

See partial zh-cn translation at README.cn.md 部分中文翻译见 README.cn.md

Nez aims to be a feature-rich 2D framework that sits on top of MonoGame/FNA. It provides a solid base for you to build a 2D game on. Some of the many features it includes are:

  • Scene/Entity/Component system with Component render layer tracking
  • SpatialHash for super fast broadphase physics lookups. You won't ever see it since it works behind the scenes but you'll love it nonetheless since it makes finding everything in your proximity crazy fast via raycasts or overlap checks.
  • AABB, circle and polygon collision/trigger detection
  • Farseer Physics (based on Box2D) integration for when you need a full physics simulation
  • efficient coroutines for breaking up large tasks across multiple frames or animation timing (Core.startCoroutine)
  • in-game debug console extendable by adding an attribute to any static method. Just press the tilde key like in the old days with Quake. Out of the box, it includes a visual physics debugging system, asset tracker, basic profiler and more. Just type 'help' to see all the commands or type 'help COMMAND' to see specific hints.
  • Dear ImGui in-game debug panels with the ability to wire up your own ImGui windows via attributes
  • in-game Component inspector. Open the debug console and use the command inspect ENTITY_NAME to display and edit fields/properties and call methods with a button click.
  • Nez.Persistence JSON, NSON (strongly typed, human readable JSON-like syntax) and binary serialization. JSON/NSON includes the ability to automatically resolve references and deal with polymorphic classes
  • extensible rendering system. Add/remove Renderers and PostProcessors as needed. Renderables are sorted by render layer first then layer depth for maximum flexibility out of the box with the ability to add your own custom sorter.
  • pathfinding support via Astar and Breadth First Search for tilemaps or your own custom format
  • deferred lighting engine with normal map support and both runtime and offline normal map generation
  • tween system. Tween any int/float/Vector/quaternion/color/rectangle field or property.
  • sprites with sprite animations, scrolling sprites, repeating sprites and sprite trails
  • flexible line renderer with configurable end caps including super smooth rounded edges or lightning bolt-like sharp edges
  • powerful particle system with added support for importing Particle Designer files at runtime
  • optimized event emitter (Emitter class) for core events that you can also add to any class of your own
  • scheduler for delayed and repeating tasks (Core.schedule method)
  • per-Scene content managers. Load your scene-specific content then forget about it. Nez will unload it for you when you change scenes.
  • customizable Scene transition system with several built in transitions
  • Verlet physics bodies for super fun, constraint-to-particle squishy physics
  • tons more stuff

Nez Systems

Setup

Install as a submodule:

  • create a Monogame Cross Platform Desktop Project
  • clone or download the Nez repository
  • add the Nez.Portable/Nez.csproj project to your solution and add a reference to it in your main project
    • if you are working with MonoGame 3.8, use Nez.Portable/Nez.MG38.csproj instead
  • make your main Game class (Game1.cs in a default project) subclass Nez.Core

If you intend to use any of the built in Effects or PostProcessors you should also copy or link the DefaultContent/effects folder into your projects Content/nez/effects folder and the DefaultContent/textures folder into Content/nez/textures. Be sure to set the Build Action to Content and enable the "Copy to output directory" property so they get copied into your compiled game. See the Nez.Samples csproj for an example on how to do this.

Note: if you get compile errors referencing a missing project.assets.json file run msbuild Nez.sln /t:restore in the root Nez folder to restore them.

Install through NuGet:

The NuGet packages are long since deprecated. The source code has been carefully commented and contains a wealth of useful information. Use the source.


All Nez shaders are compiled for OpenGL so be sure to use the DesktopGL template, not DirectX! Nez only supports OpenGL out of the box to keep things compatible across Android/iOS/Mac/Linux/Windows.

If you are developing a mobile application you will need to enable touch input by calling Input.Touch.EnableTouchSupport().

Samples Repository

You can find the samples repo here. It contains a variety of sample scenes that demonstrate the basics of getting stuff done with Nez. This YouTube playlist also has a few relevant videos.

For reference, you can also access Nez's documentation here.

Using Nez with FNA

Note that you have to install the required FNA native libs per the FNA documentation. Here is what you need to do to get up and running with Nez + FNA:

  • clone this repo recursively
  • open the Nez solution (Nez/Nez.sln) and build it. This will cause the NuGet packages to refresh.
  • download/clone FNA
  • open your game's project and add a reference to FNA and Nez.FNA
  • (optionally) add references to Nez.FNA.ImGui or Nez.FNA.FarseerPhysics if you need them

The folder structure the cscproj files expect is something like this:

  • TopLevelFolderHousingEverything
    • FNA
    • YourGameProject
    • Nez

Alternatively, you can use the Nez + FNA template which works for Visual Studio and VS Code available here.

Acknowledgements/Attributions

Bits and pieces of Nez were cherry-picked from various places around the internet. If you see something in Nez that looks familiar open an issue with the details so that we can properly attribute the code.

I want to extend a special thanks to three people and their repos listed below. The Monocle Engine and MonoGame.Extended allowed me to get up and running with MonoGame nearly instantly when I was first evaluating if it would be a good alternative to use for making games. libGDX scene2D UI was ported over to Nez to get a jump start on a UI as well. Nez uses a bunch of concepts and code from all three of these repos.

Maddy Thorson's fantastic Monocle Engine

Dylan Wilson's excellent MonoGame.Extended and his initial work on converted Farseer Physics Engine to a Portable Class Library. Farseer is Microsoft Permissive v1.1 licensed.

Nathan Sweet's libGDX Scene2D UI libGDX. Nez UI is based on libGDX Scene2D which is Apache licensed.