LDtkMonogame.Codegen 1.2.0

dotnet tool install --global LDtkMonogame.Codegen --version 1.2.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local LDtkMonogame.Codegen --version 1.2.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=LDtkMonogame.Codegen&version=1.2.0
nuke :add-package LDtkMonogame.Codegen --version 1.2.0

<p align="center"> <img src="https://raw.githubusercontent.com/IrishBruse/LDtkMonogame/main/Icon.png" height="128px"/> </p>

<p align="center"> <a href="https://ldtk.io/go/discord"><img src="https://img.shields.io/discord/761549092677353513?color=%236370f4&label=Discord" alt="Discord Link"></a>   <a href="https://github.com/deepnight/ldtk"><img src="https://img.shields.io/badge/LDtk-1.5.3-yellow" alt=""></a> </p>

LDtkMonogame is an level importer for the LDtk level editor

Getting Started

The easiest way to start using LDtkMonogame is to import it into the project using NuGet package.

Make sure to import the namespace at the top

using LDtk;
// Optional
using LDtk.Renderer;

LDtk.Renderer is a premade renderer for the levels, you can create your own if you have more specific needs LDtkRenderer.cs is an example of how to make one. Or you can inherit it and extend it.

To get started loading ldtk files load the file in Initialize.

LDtkFile file = LDtkFile.FromFile("World", Content);
LDtkFile file = LDtkFile.FromFile("Data/World.ldtk");

Then load the world right after for now ldtk only supports one file but make sure to enable the multiworlds flag in the project settings under advanced.

LDtkWorld world = file.LoadWorld(Worlds.World.Iid);

The Worlds.World.Iid is generated from the ldtkgen tool and is recommended that you use it for static typing of entities and levels.
It is a class within in a class that represents the world name and the levels name and holds the iid you can use to load that specific level.

Create the renderer in Initialize.

LDtkRenderer renderer = new LDtkRenderer(spriteBatch, Content);
LDtkRenderer renderer = new LDtkRenderer(spriteBatch);

Prerender Levels

foreach (LDtkLevel level in world.Levels)
{
    renderer.PrerenderLevel(level);
}

Now to render the level and entities we loaded in Draw

GraphicsDevice.Clear(world.BgColor);

spriteBatch.Begin(samplerState: SamplerState.PointClamp);
{
    foreach (LDtkLevel level in world.Levels)
    {
        renderer.RenderPrerenderedLevel(level);
    }
}
spriteBatch.End();

Showcase

Unnamed

screenshot

by Fypur

Play the game on Itch

Example Game

screenshot

by IrishBruse

Source code here

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
1.2.0 207 1/25/2024
1.1.2 286 9/8/2023
1.1.0 166 6/8/2023
1.0.1 390 1/15/2023
1.0.0 328 1/3/2023
0.7.0 473 7/26/2022
0.6.5 367 7/20/2022
0.6.4 390 6/14/2022
0.6.3 384 6/14/2022
0.6.2 446 5/10/2022
0.6.1 388 5/10/2022
0.6.0 413 5/10/2022
0.5.0 388 5/9/2022
0.4.0 315 12/23/2021