Categorygithub.com/solarlune/ldtkgo
modulepackage
0.10.0
Repository: https://github.com/solarlune/ldtkgo.git
Documentation: pkg.go.dev

# README

LDtk-Go

LDtk-Go is a loader for LDtk v0.9.3 projects written in pure Go.

Screenshot

Generally, you first load a project using ldtkgo.Open() or ldtkgo.Read(); afterward, you render the layers out to images, and then draw them onscreen with a rendering or game development framework, like ebiten, Pixel, raylib-go, or raylib-go-plus. An example that uses ebiten for rendering is included.

All of the major elements of LDtk should be supported, including Levels, Layers, Tiles, AutoLayers, IntGrids, Entities, and Properties.

Pkg.go.dev docs

Loading Projects

Using LDtk-Go is simple.

First, you load the LDTK project, either with ldtkgo.Open() or ldtkgo.Read(). After that, you have access to most of the useful parts of the entire LDTK project. You can then render the map using the included renderer if you're using Ebitengine.

package main

import (
	"embed"

	"github.com/solarlune/ldtkgo"
	renderer "github.com/solarlune/ldtkgo/renderer/ebitengine"
)

var ldtkProject *ldtkgo.Project
var ebitenRenderer *renderer.Renderer

//go:embed *.ldtk *.png
var fileSystem embed.FS

func main() {
	// Load the LDtk Project
	ldtkProject, err := ldtkgo.Open("example.ldtk", fileSystem)

	if err != nil {
		panic(err)
	}

	// ldtkProject now contains all data from the file.
	// If you'd like to render it, you could use the included renderer that uses Ebitengine:

	// Choose a level...
	level := ldtkProject.Levels[0]

	// Create a new renderer...
	ebitenRenderer = renderer.New(ldtkProject)

	// ... And render the tiles for the level out to layers, which will be *ebiten.Images. We can then retrieve them to draw in a Draw() loop later.
	ebitenRenderer.Render(level)
}


Running the Example

cd to the example directory, and then call go run . to run the example (as it's self-contained within its directory). The console will give instructions for interacting with the example.

Anything Else?

The core LDtk loader requires the encoding/json and image package. The Ebiten renderer requires Ebitengine as well, of course.

To-do

  • Add map clipping / viewports to Ebitengine renderer

# Packages

No description provided by the author

# Functions

Open loads the LDtk project from the filepath specified using the file system provided.
Read reads the LDtk project using the specified slice of bytes.

# Constants

LayerType constants indicating a Layer's type.
LayerType constants indicating a Layer's type.
LayerType constants indicating a Layer's type.
LayerType constants indicating a Layer's type.
WorldLayout constants indicating direction or layout system for Worlds.
WorldLayout constants indicating direction or layout system for Worlds.
WorldLayout constants indicating direction or layout system for Worlds.
WorldLayout constants indicating direction or layout system for Worlds.

# Structs

BGImage represents a Level's background image as definied withing LDtk (the filepath, the scale, etc).
An Entity represents an Entity as placed in the LDtk level.
An Entity represents an Entitydefintion as defined in the entities.
Integer indicates the value for an individual "Integer Object" on the IntGrid layer.
Layer represents a Layer, which can be of multiple types (Entity, AutoTile, Tile, or IntGrid).
Level represents a Level in an LDtk Project.
Project represents a full LDtk Project, allowing you access to the Levels within as well as some project-level properties.
Property represents custom Properties created and customized on Entities.
Tile represents a graphical tile (whether automatic or manually placed).
TileRect represents the rectangle from which an Entity tile is.
No description provided by the author

# Type aliases

EnumSet represents a set of Enums applied to tiles; this is just for convenience so you can see if a Tile contains an enum easily.