Documentation
¶
Overview ¶
Package ebitentiled provides utilities for parsing and loading Tiled Editor maps (`.tmj`) into a domain model suitable for use with the Ebitengine game engine. It handles the conversion from the Tiled JSON format to a more ergonomic structure for tile-based gameplay.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Tilemap ¶
type Tilemap struct {
CompressionLevel int // The compression level to use for tile layer data (defaults to -1, which means to use the algorithm default)
Height int // Number of tile rows.
Infinite bool // Whether the map has infinite dimensions.
Layers []*layer // Array of layers.
Orientation string
RenderOrder string
TiledVersion string
TileHeight int // Map grid height.
Tilesets []*tilesetSource // An array of external tilesets.
TileWidth int // Map grid width
Type string // the value is always 'map' since Tiled v1.0.
Width int // Number of tile columns
WidthInPixels int // Map's width in pixels.
HeightInPixels int // Map's height in pixels.
// contains filtered or unexported fields
}
Tilemap represents a map exported from Tiled editor.
For more information check out https://doc.mapeditor.org/en/stable/reference/json-map-format/#map.
func NewTilemap ¶
NewTilemap loads a Tilemap from a `.tmj` file at the specified path. It parses the JSON structure, resolves relative paths for tilesets, and pre-caches tiles for efficient rendering.
Example:
tilemap, err := ebitentiled.NewTilemap("./assets/map.tmj")
if err != nil {
log.Fatal(err)
}
func (*Tilemap) Draw ¶
Draw renders the visible layers of the tilemap onto the provided Ebitengine image. It automatically handles frustum culling to ensure high performance even on very large maps.
Parameters:
- screen: The target *ebiten.Image where the map will be drawn (usually the main game screen).
- viewport: The camera configuration defining which part of the map is visible.
Implementation details: The method iterates through each layer in the order they were defined in Tiled (bottom to top). For each layer, it only loops through the tiles identified by calculateVisibleIndices. Screen coordinates are calculated by subtracting the viewport's position from the tile's world position:
screenX = (tileColumn * tileWidth) - viewportX
type Viewport ¶
Viewport represents the visible window of the game world. It defines which part of the map is currently being rendered to the screen.
Example:
v := Viewport{X: 100, Y: 50, Width: 640, Height: 480}
This viewport starts at pixel (100, 50) in the world and covers an area of 640x480 pixels.
func NewViewport ¶
NewViewport creates a new Viewport with the given position and dimensions.
