tiled

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TMXAssetType = "tmx"
	TSXAssetType = "tsx"
	TXAssetType  = "tx"
)
View Source
const (
	TILE_FLIP_HORIZONTAL  = 0x80000000
	TILE_FLIP_VERTICAL    = 0x40000000
	TILE_FLIP_DIAGONAL    = 0x20000000
	TILE_FLIP_ROTATED_HEX = 0x10000000
	TILE_ID_MASK          = 0x1FFFFFFF
)
View Source
const (
	ColumnsAttr         = "columns"
	EncodingAttr        = "encoding"
	FirstGIDAttr        = "firstgid"
	GIDAttr             = "gid"
	HeightAttr          = "height"
	IDAttr              = "id"
	InfiniteAttr        = "infinite"
	LockedAttr          = "locked"
	NameAttr            = "name"
	NextLayerIDAttr     = "nextlayerid"
	NextObjectIDAttr    = "nextobjectid"
	ObjectAlignmentAttr = "objectalignment"
	OrientationAttr     = "orientation"
	PropertyTypeAttr    = "propertytype"
	RenderOrderAttr     = "renderorder"
	SourceAttr          = "source"
	SpacingAttr         = "spacing"
	TemplateAttr        = "template"
	TileCountAttr       = "tilecount"
	TileHeightAttr      = "tileheight"
	TileWidthAttr       = "tilewidth"
	TiledVersionAttr    = "tiledversion"
	ValueAttr           = "value"
	VersionAttr         = "version"
	VisibleAttr         = "visible"
	WidthAttr           = "width"
	XAttr               = "x"
	YAttr               = "y"
)
View Source
const (
	ErrWhileDrawingLayer = "tiled: error while drawing layer"
)

Variables

This section is empty.

Functions

func Draw

func Draw(ctx finch.Context, img *ebiten.Image, tmx *TMX)

Draw attempts to render the entire TMX map onto the provided image. If the map is larger than the image, only the top-left portion will be drawn.

func DrawLayer added in v0.0.4

func DrawLayer(ctx finch.Context, img *ebiten.Image, tmx *TMX, layerName string)

DrawLayer attempts to render a specific layer of the TMX map onto the provided image. If the map is larger than the image, only the top-left portion will be drawn.

func DrawLayerRegion added in v0.0.4

func DrawLayerRegion(ctx finch.Context, img *ebiten.Image, tmx *TMX, layerName string, region geom.Rect64)

DrawLayerRegion renders only the specified region of a specific layer of the TMX map onto the provided image.

func DrawObject added in v0.0.9

func DrawObject(ctx finch.Context, img *ebiten.Image, tmx *TMX, obj *Object, transform ebiten.GeoM, view ebiten.GeoM)

DrawObject renders a specific drawable object from the TMX map using the provided view matrix.

func DrawRegion

func DrawRegion(ctx finch.Context, img *ebiten.Image, tmx *TMX, region geom.Rect64)

DrawRegion renders only the specified region of the TMX map onto the provided image.

func DrawScene

func DrawScene(ctx finch.Context, img *ebiten.Image, tmx *TMX, viewport geom.Rect64, viewMatrix ebiten.GeoM)

DrawScene renders the TMX map as seen through a camera, using the provided viewport and view matrix. This is typically used for rendering the map in a game scene where the camera can move and zoom.

func DrawSceneLayer added in v0.0.4

func DrawSceneLayer(ctx finch.Context, img *ebiten.Image, tmx *TMX, layerName string, viewport geom.Rect64, viewMatrix ebiten.GeoM)

DrawSceneLayer renders a specific layer of the TMX map as seen through a camera, using the provided viewport and view matrix. This is typically used for rendering the map in a game scene where the camera can move and zoom.

func GetTSXImg added in v0.0.2

func GetTSXImg(file finch.AssetFile) (*ebiten.Image, error)

GetTSXImg retrieves the image associated with a TSX asset.

func GetTXImg added in v0.0.7

func GetTXImg(file finch.AssetFile) (*ebiten.Image, error)

GetTXImg retrieves the image associated with a TX asset.

Images are retrieved from the TSX asset referenced by the TX.

func MustGetTSXImg added in v0.0.2

func MustGetTSXImg(file finch.AssetFile) *ebiten.Image

MustGetTSXImg is like GetTSXImg but panics if the asset cannot be found.

func MustGetTXImg added in v0.0.7

func MustGetTXImg(file finch.AssetFile) *ebiten.Image

MustGetTXImg is like GetTXImg but panics if the asset cannot be found.

func RegisterTiledAssetImporters added in v0.0.7

func RegisterTiledAssetImporters()

Types

type AttrBool

type AttrBool bool

func UnmarshalAttrBool

func UnmarshalAttrBool(s string) (AttrBool, error)

func (AttrBool) Bool

func (b AttrBool) Bool() bool

func (AttrBool) String added in v0.0.8

func (b AttrBool) String() string

type AttrInt

type AttrInt int

func UnmarshalAttrInt

func UnmarshalAttrInt(s string) (AttrInt, error)

func (AttrInt) Int

func (i AttrInt) Int() int

func (AttrInt) String added in v0.0.8

func (i AttrInt) String() string

type AttrString

type AttrString string

func UnmarshalAttrString

func UnmarshalAttrString(s string) (AttrString, error)

func (AttrString) String

func (s AttrString) String() string

type DataChunk added in v0.0.7

type DataChunk struct {
	Attrs TiledXMLAttrTable `xml:",any,attr"`
	Data  string            `xml:",chardata"`
}

func (DataChunk) Bounds added in v0.0.8

func (chunk DataChunk) Bounds() geom.Rect64

func (DataChunk) Height added in v0.0.7

func (chunk DataChunk) Height() int

func (DataChunk) Width added in v0.0.7

func (chunk DataChunk) Width() int

func (DataChunk) X added in v0.0.7

func (chunk DataChunk) X() int

func (DataChunk) Y added in v0.0.7

func (chunk DataChunk) Y() int

type DrawMode

type DrawMode int
const (
	DrawModeNormal DrawMode = iota
	DrawModeRegional
	DrawModeScene
)

type Encoding added in v0.0.7

type Encoding int
const (
	TMXEncodingCSV Encoding = iota
	TMXEncodingBase64
)

func (Encoding) IsValid added in v0.0.7

func (e Encoding) IsValid() bool

func (Encoding) MarshalJSON added in v0.0.7

func (e Encoding) MarshalJSON() ([]byte, error)

func (Encoding) String added in v0.0.7

func (e Encoding) String() string

func (*Encoding) UnmarshalJSON added in v0.0.7

func (e *Encoding) UnmarshalJSON(data []byte) error

type FlipFlags added in v0.0.7

type FlipFlags uint8
const (
	FLIP_NONE       FlipFlags = 0
	FLIP_HORIZONTAL FlipFlags = 1 << iota
	FLIP_VERTICAL
	FLIP_DIAGONAL
	FLIP_ROTATED_HEX
)

func (FlipFlags) FlipDiagonal added in v0.0.7

func (f FlipFlags) FlipDiagonal() bool

func (FlipFlags) FlipHorizontal added in v0.0.7

func (f FlipFlags) FlipHorizontal() bool

func (FlipFlags) FlipRotatedHex added in v0.0.7

func (f FlipFlags) FlipRotatedHex() bool

func (FlipFlags) FlipVertical added in v0.0.7

func (f FlipFlags) FlipVertical() bool

type Image added in v0.0.7

type Image struct {
	Attrs TiledXMLAttrTable `xml:",any,attr"`
}

func (Image) Height added in v0.0.7

func (img Image) Height() int

func (Image) Source added in v0.0.7

func (img Image) Source() string

func (Image) Width added in v0.0.7

func (img Image) Width() int

type Layer added in v0.0.7

type Layer struct {
	Attrs      TiledXMLAttrTable `xml:",any,attr"`
	Data       *LayerData        `xml:"data"`
	Properties []*Property       `xml:"properties>property"`
	// contains filtered or unexported fields
}

func (Layer) Bounds added in v0.0.8

func (layer Layer) Bounds() geom.Rect64

func (Layer) Height added in v0.0.7

func (layer Layer) Height() int

func (Layer) ID added in v0.0.7

func (layer Layer) ID() int

func (Layer) IsVisible added in v0.0.7

func (layer Layer) IsVisible() bool

func (Layer) Name added in v0.0.7

func (layer Layer) Name() string

func (Layer) PropertyOfType added in v0.0.9

func (layer Layer) PropertyOfType(ptype string) (*Property, bool)

func (Layer) Width added in v0.0.7

func (layer Layer) Width() int

type LayerData added in v0.0.7

type LayerData struct {
	Attrs  TiledXMLAttrTable `xml:",any,attr"`
	Chunks []*DataChunk      `xml:"chunk"`
	Data   string            `xml:",chardata"`
}

func (LayerData) Encoding added in v0.0.7

func (data LayerData) Encoding() Encoding

type LayerPartitions

type LayerPartitions map[geom.Rect64][]*Tile

type Object added in v0.0.7

type Object struct {
	Attrs      TiledXMLAttrTable `xml:",any,attr"`
	Properties []*Property       `xml:"properties>property"`
	Tileset    *Tileset          `xml:"tileset"`
	// contains filtered or unexported fields
}

func (Object) GID added in v0.0.9

func (obj Object) GID() int

func (Object) HasTemplate added in v0.0.7

func (obj Object) HasTemplate() bool

func (Object) Height added in v0.0.7

func (obj Object) Height() int

func (Object) ID added in v0.0.7

func (obj Object) ID() int

func (Object) Name added in v0.0.7

func (obj Object) Name() string

func (Object) PropertyOfType added in v0.0.7

func (obj Object) PropertyOfType(ptype string) (*Property, bool)

func (Object) Template added in v0.0.7

func (obj Object) Template() string

func (Object) Width added in v0.0.7

func (obj Object) Width() int

func (Object) X added in v0.0.7

func (obj Object) X() int

func (Object) Y added in v0.0.7

func (obj Object) Y() int

type ObjectAlignment added in v0.0.9

type ObjectAlignment int
const (
	ObjectAlignmentUnspecified ObjectAlignment = iota
	ObjectAlignmentTopLeft
	ObjectAlignmentTop
	ObjectAlignmentTopRight
	ObjectAlignmentLeft
	ObjectAlignmentCenter
	ObjectAlignmentRight
	ObjectAlignmentBottomLeft
	ObjectAlignmentBottom
	ObjectAlignmentBottomRight
)

func (ObjectAlignment) IsValid added in v0.0.9

func (oa ObjectAlignment) IsValid() bool

func (ObjectAlignment) MarshalJSON added in v0.0.9

func (oa ObjectAlignment) MarshalJSON() ([]byte, error)

func (ObjectAlignment) String added in v0.0.9

func (oa ObjectAlignment) String() string

func (*ObjectAlignment) UnmarshalJSON added in v0.0.9

func (oa *ObjectAlignment) UnmarshalJSON(data []byte) error

type ObjectGroup added in v0.0.7

type ObjectGroup struct {
	Attrs      TiledXMLAttrTable `xml:",any,attr"`
	Objects    []*Object         `xml:"object"`
	Properties []*Property       `xml:"properties>property"`
}

func (ObjectGroup) ID added in v0.0.7

func (og ObjectGroup) ID() int

func (ObjectGroup) Name added in v0.0.7

func (og ObjectGroup) Name() string

func (ObjectGroup) PropertyOfType added in v0.0.9

func (og ObjectGroup) PropertyOfType(ptype string) (*Property, bool)

type Offset added in v0.0.7

type Offset struct {
	Attrs TiledXMLAttrTable `xml:",any,attr"`
}

func (Offset) X added in v0.0.7

func (offset Offset) X() int

func (Offset) Y added in v0.0.7

func (offset Offset) Y() int

type Orientation added in v0.0.7

type Orientation int
const (
	Orthogonal Orientation = iota
	Isometric
	Staggered
	Hexagonal
)

func (Orientation) IsValid added in v0.0.7

func (o Orientation) IsValid() bool

func (Orientation) MarshalJSON added in v0.0.7

func (o Orientation) MarshalJSON() ([]byte, error)

func (Orientation) String added in v0.0.7

func (o Orientation) String() string

func (*Orientation) UnmarshalJSON added in v0.0.7

func (o *Orientation) UnmarshalJSON(data []byte) error

type Property added in v0.0.7

type Property struct {
	Attrs      TiledXMLAttrTable `xml:",any,attr"`
	Properties []*Property       `xml:"properties>property"`
}

func (Property) Name added in v0.0.7

func (prop Property) Name() string

func (Property) PropertyOfType added in v0.0.7

func (prop Property) PropertyOfType(ptype string) (*Property, bool)

func (Property) PropertyType added in v0.0.7

func (prop Property) PropertyType() string

func (Property) Type added in v0.0.7

func (prop Property) Type() string

func (Property) Value added in v0.0.7

func (prop Property) Value() string

type RenderOrder added in v0.0.7

type RenderOrder int
const (
	TMXRightDown RenderOrder = iota
	TMXRightUp
	TMXLeftDown
	TMXLeftUp
)

func (RenderOrder) IsValid added in v0.0.7

func (ro RenderOrder) IsValid() bool

func (RenderOrder) MarshalJSON added in v0.0.7

func (ro RenderOrder) MarshalJSON() ([]byte, error)

func (RenderOrder) String added in v0.0.7

func (ro RenderOrder) String() string

func (*RenderOrder) UnmarshalJSON added in v0.0.7

func (ro *RenderOrder) UnmarshalJSON(data []byte) error

type TMX

type TMX struct {
	Attrs        TiledXMLAttrTable `xml:",any,attr"`
	ObjectGroups []*ObjectGroup    `xml:"objectgroup"`
	Tilesets     []*Tileset        `xml:"tileset"`
	Layers       []*Layer          `xml:"layer"`
}

TMX represents a deserialized Tiled tmx file.

func GetTMX

func GetTMX(file finch.AssetFile) (*TMX, error)

GetTMX retrieves a TMX asset by its file reference.

func MustGetTMX

func MustGetTMX(file finch.AssetFile) *TMX

MustGetTMX is like GetTMX but panics if the asset cannot be found.

func (TMX) Bounds added in v0.0.8

func (tmx TMX) Bounds() geom.Rect64

func (TMX) Height

func (tmx TMX) Height() int

func (TMX) IsInfinite

func (tmx TMX) IsInfinite() bool

func (TMX) LayerByName added in v0.0.9

func (tmx TMX) LayerByName(name string) *Layer

func (TMX) LayerByProperty added in v0.0.9

func (tmx TMX) LayerByProperty(ptype string, pvalue any) *Layer

func (TMX) ObjectGroupByName added in v0.0.9

func (tmx TMX) ObjectGroupByName(name string) *ObjectGroup

func (TMX) ObjectGroupByProperty added in v0.0.9

func (tmx TMX) ObjectGroupByProperty(ptype string, pvalue any) *ObjectGroup

func (TMX) Orientation

func (tmx TMX) Orientation() Orientation

func (TMX) RenderOrder

func (tmx TMX) RenderOrder() RenderOrder

func (TMX) TileHeight

func (tmx TMX) TileHeight() int

func (TMX) TileWidth

func (tmx TMX) TileWidth() int

func (TMX) TiledVersion

func (tmx TMX) TiledVersion() string

func (TMX) Version

func (tmx TMX) Version() string

func (TMX) Width

func (tmx TMX) Width() int

type TSX

type TSX struct {
	Attrs      TiledXMLAttrTable `xml:",any,attr"`
	TileOffset *Offset           `xml:"tileoffset"`
	Image      *Image            `xml:"image"`
}

func GetTSX

func GetTSX(file finch.AssetFile) (*TSX, error)

GetTSX retrieves a TSX asset by its file reference.

func GetTXTSX added in v0.0.7

func GetTXTSX(file finch.AssetFile) (*TSX, error)

GetTXTSX retrieves the TSX asset referenced by a TX asset.

func MustGetTSX

func MustGetTSX(file finch.AssetFile) *TSX

MustGetTSX is like GetTSX but panics if the asset cannot be found.

func MustGetTXTSX added in v0.0.7

func MustGetTXTSX(file finch.AssetFile) *TSX

MustGetTXTSX is like GetTXTSX but panics if the asset cannot be found.

func (TSX) Columns

func (tsx TSX) Columns() int

func (TSX) Name

func (tsx TSX) Name() string

func (TSX) ObjectAlignment added in v0.0.9

func (tsx TSX) ObjectAlignment() geom.Point64

func (TSX) Spacing

func (tsx TSX) Spacing() int

func (TSX) TileCount

func (tsx TSX) TileCount() int

func (TSX) TileHeight

func (tsx TSX) TileHeight() int

func (TSX) TileOffsetX added in v0.0.9

func (tsx TSX) TileOffsetX() int

func (TSX) TileOffsetY added in v0.0.9

func (tsx TSX) TileOffsetY() int

func (TSX) TileWidth

func (tsx TSX) TileWidth() int

func (TSX) TiledVersion

func (tsx TSX) TiledVersion() string

func (TSX) Version

func (tsx TSX) Version() string

type TX added in v0.0.7

type TX struct {
	Attrs   TiledXMLAttrTable `xml:",any,attr"`
	Tileset *Tileset          `xml:"tileset"`
	Object  *Object           `xml:"object"`
}

func GetTX added in v0.0.7

func GetTX(file finch.AssetFile) (*TX, error)

GetTX retrieves a TX asset by its file reference.

func MustGetTX added in v0.0.7

func MustGetTX(file finch.AssetFile) *TX

MustGetTX is like GetTX but panics if the asset cannot be found.

type Tile

type Tile struct {
	GID           uint32
	TsxSrc        string
	X, Y          float64
	Width, Height float64
	Flags         FlipFlags
}

type TiledObjectFactory added in v0.0.9

type TiledObjectFactory[T any] struct {
	FromTemplate func(instance *Object, template *TX, tmx *TMX) T
	FromObject   func(obj *Object, tmx *TMX) T
}

type TiledXMLAttr

type TiledXMLAttr interface {
	String() string
}

type TiledXMLAttrTable

type TiledXMLAttrTable map[string]TiledXMLAttr

func (*TiledXMLAttrTable) UnmarshalXMLAttr

func (m *TiledXMLAttrTable) UnmarshalXMLAttr(attr xml.Attr) error

type Tileset added in v0.0.7

type Tileset struct {
	Attrs TiledXMLAttrTable `xml:",any,attr"`
}

func (Tileset) FirstGID added in v0.0.7

func (ts Tileset) FirstGID() uint32

func (Tileset) Source added in v0.0.7

func (ts Tileset) Source() string

Jump to

Keyboard shortcuts

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