tilemap

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultChunkSize int32 = 16 // in tiles
)

Variables

View Source
var (
	ErrNoTmxData       = errors.New("no Tmx data set")
	ErrInvalidTmxData  = errors.New("invalid Tmx data")
	ErrTilesetNotFound = errors.New("tileset not found")
	ErrTileNotFound    = errors.New("tile not found")
	ErrTilesetSource   = errors.New("tileset source is empty")
)

Functions

This section is empty.

Types

type Chunk

type Chunk struct {
	// contains filtered or unexported fields
}

func (*Chunk) Flush

func (c *Chunk) Flush()

type Data

type Data struct {
	X, Y     float32        // World position
	TileID   uint32         // Tile ID
	TsIdx    int            // Tileset index
	FlipFlag tiled.FlipFlag // Flip flags
}

func GetTileData

func GetTileData(gid uint32, tmx *tiled.Tmx, x, y float32) (Data, bool)

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame represents the visible region of a tilemap in world coordinates.

func (*Frame) Bounds

func (f *Frame) Bounds() (minX, minY, maxX, maxY float32)

func (*Frame) Height

func (f *Frame) Height() float32

func (*Frame) Max

func (f *Frame) Max() (x, y float32)

func (*Frame) Min

func (f *Frame) Min() (x, y float32)

func (*Frame) Set

func (f *Frame) Set(frame [4]float32)

func (*Frame) Width

func (f *Frame) Width() float32

type Iterator

type Iterator struct {
	// contains filtered or unexported fields
}

Iterator provides a way to iterate over tiles in the visible frame of a tilemap.

func (*Iterator) Next

func (it *Iterator) Next() []Data

type Layer

type Layer struct {
	*hash.Grid[*Chunk]
}

func (*Layer) Flush

func (l *Layer) Flush()

type Map

type Map struct {
	Tmx *tiled.Tmx
	// contains filtered or unexported fields
}

Map represents the decoded tilemap data from a Tmx file.

It provides methods to retrieve tile data, manage layers, and buffer the map for rendering.

func NewMap

func NewMap() *Map

func (*Map) BufferFrame

func (tm *Map) BufferFrame() error

BufferFrame buffers tile data for current frame.

func (*Map) Flush

func (tm *Map) Flush()

Flush clears all layers and their chunks from the map.

func (*Map) Frame

func (tm *Map) Frame() *Frame

Frame returns the visible region of the tilemap in world coordinates. Use this to get or set the visible region of the map.

Frame only returns the dimensions of the visible region of the tilemap. It does not update or buffer the map for rendering.

func (*Map) GetTileset

func (tm *Map) GetTileset(index int) (*tiled.Tileset, error)

func (*Map) Itr

func (tm *Map) Itr() Iterator

Itr returns an iterator for the map. Use this for iterating over tiles in the visible frame.

func (*Map) SetTmx

func (tm *Map) SetTmx(tmx *tiled.Tmx) error

SetTmx sets the Tmx data for the map and builds the underlying structures of the map. Setting a new Tmx will clear any existing layers data, but will not reset the frame.

type Region

type Region struct {
	MinX, MinY int32
	MaxX, MaxY int32
}

Region represents a rectangular region in tile coordinates.

func (*Region) Equals

func (r *Region) Equals(other *Region) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL