etiled

package module
v0.0.0-...-85a7efe Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 11 Imported by: 0

README

Ebitengine Tiled

Discord Subreddit

This project is built to parse and render tiled maps

Features

  • Ability to use a provided Filesystem.
  • Ability to render animated tile maps

Example

    # Get the latest version of the library
    go get github.com/bird-mtn-dev/ebitengine-tiled
    // Import the library
    import (
        etiled "github.com/bird-mtn-dev/ebitengine-tiled"
    )

    // Load the xml output from tiled during the initilization of the Scene.
    // Note that OpenTileMap will attempt to load the associated tilesets and tile images 
    Tilemap = etiled.OpenTileMap("assets/tilemap/base.tmx")
    // Defines the draw parameters of the tilemap tiles
    Tilemap.Zoom = 1


    // Call Update on the Tilemap during the ebitengine Update loop
    Tilemap.Update()

    // Call Draw on the Tilemap during the ebitegine Draw loop to draw all the layers in the tilemap
    Tilemap.Draw(worldScreen)

    // This loop will draw all the Object Groups in the Tilemap.
    for idx := range Tilemap.ObjectGroups {
        Tilemap.ObjectGroups[idx].Draw(worldScreen)
    }

    // You can draw a specific Layer by calling
    Tilemap.GetLayerByName("layer1").Draw(worldScreen)

    // You can draw a specific Object Group by calling
    Tilemap.GetObjectGroupByName("ojbect group 1").Draw(worldScreen)

License

The template is licensed under the MIT license.

Maintainers

Contributing

Want to help improve the template? Check out our current issues.

Want to know the steps on how to start contributing, take a look at the open source guide.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetImageFromFilePath

func GetImageFromFilePath(filePath string, filesystem fs.FS) *ebiten.Image

Types

type Data

type Data struct {
	Encoding string
	Values   [][]int
}

func (*Data) UnmarshalXML

func (s *Data) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Frame

type Frame struct {
	XMLName  xml.Name `xml:"frame"`
	TileId   int      `xml:"tileid,attr"`
	Duration int      `xml:"duration,attr"`
}

type GroupLayer

type GroupLayer struct {
	XMLName      xml.Name             `xml:"group"`
	Name         string               `xml:"name,attr"`
	Layers       []Layer              `xml:"layer"`
	ObjectGroups []TileMapObjectGroup `xml:"objectgroup"`
	GroupLayers  []GroupLayer         `xml:"group"`
	Properties   []Property           `xml:"properties>property"`
	Tilemap      *TileMap
}

func (*GroupLayer) Draw

func (groupLayer *GroupLayer) Draw(screen *ebiten.Image)

func (*GroupLayer) UnmarshalXML

func (gl *GroupLayer) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type ImageDefinition

type ImageDefinition struct {
	XMLName     xml.Name `xml:"image"`
	Source      string   `xml:"source,attr"`
	Width       int      `xml:"width,attr"`
	Height      int      `xml:"height,attr"`
	LoadedImage *ebiten.Image
}

type Layer

type Layer struct {
	XMLName    xml.Name   `xml:"layer"`
	Id         int        `xml:"id,attr"`
	Name       string     `xml:"name,attr"`
	Width      int        `xml:"width,attr"`
	Height     int        `xml:"height,attr"`
	Properties []Property `xml:"properties>property"`
	Data       Data       `xml:"data"`
	Tilemap    *TileMap
}

func (*Layer) Draw

func (layer *Layer) Draw(screen *ebiten.Image)

func (*Layer) GetId

func (l *Layer) GetId() string

func (*Layer) UnmarshalXML

func (l *Layer) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type NodeExists

type NodeExists struct {
}

type Point

type Point struct {
	X float64
	Y float64
}

type Polygon

type Polygon struct {
	XMLName xml.Name `xml:"polygon"`
	Points  []Point
}

func (*Polygon) UnmarshalXML

func (s *Polygon) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type Property

type Property struct {
	Name  string `xml:"name,attr"`
	Type  string `xml:"type,attr"`
	Value string `xml:"value,attr"`
}

type Tile

type Tile struct {
	XMLName       xml.Name   `xml:"tile"`
	Id            int        `xml:"id,attr"`
	Properties    []Property `xml:"properties>property"`
	PreviousTick  int
	PreviousFrame *int
	Animation     []Frame            `xml:"animation>frame"`
	ObjectGroup   TileSetObjectGroup `xml:"objectgroup"`
}

type TileMap

type TileMap struct {
	XMLName      xml.Name `xml:"map"`
	Version      string   `xml:"version,attr"`
	TiledVersion string   `xml:"tiledversion,attr"`
	Path         string
	Orientation  string               `xml:"orientation,attr"`
	RenderOrder  string               `xml:"renderorder,attr"`
	Width        int                  `xml:"width,attr"`
	Height       int                  `xml:"height,attr"`
	TileWidth    int                  `xml:"tilewidth,attr"`
	TileHeight   int                  `xml:"tileheight,attr"`
	Infinite     bool                 `xml:"infinite,attr"`
	TileSets     []TileSetDefinition  `xml:"tileset"`
	GroupLayers  []GroupLayer         `xml:"group"`
	Layers       []Layer              `xml:"layer"`
	ObjectGroups []TileMapObjectGroup `xml:"objectgroup"`
	Properties   []Property           `xml:"properties>property"`

	AllCollisions []*TileSetObject
	// contains filtered or unexported fields
}

func OpenTileMap

func OpenTileMap(file string) *TileMap

This opens a .tmx file based on the current working directory.

An example call would looke like: etiled.OpenTileMap("assets/tilemap/base.tmx")

func OpenTileMapWithFileSystem

func OpenTileMapWithFileSystem(file string, filesystem fs.FS) *TileMap

func (*TileMap) Draw

func (tileMap *TileMap) Draw(screen *ebiten.Image)

func (*TileMap) GetDimensions

func (tileMap *TileMap) GetDimensions() (int, int)

func (*TileMap) GetGroupLayerByName

func (tileMap *TileMap) GetGroupLayerByName(name string) *GroupLayer

func (*TileMap) GetLayerByName

func (tileMap *TileMap) GetLayerByName(name string) *Layer

func (*TileMap) GetObjectGroupByName

func (tileMap *TileMap) GetObjectGroupByName(name string) *TileMapObjectGroup

func (*TileMap) GetTileSetByTileId

func (tileMap *TileMap) GetTileSetByTileId(id int) (*TileSet, int)

func (*TileMap) Update

func (tileMap *TileMap) Update()

type TileMapObject

type TileMapObject struct {
	XMLName xml.Name `xml:"object"`
	Id      int      `xml:"id,attr"`
	Gid     int      `xml:"gid,attr"`
	X       float64  `xml:"x,attr"`
	Y       float64  `xml:"y,attr"`
	Width   int      `xml:"width,attr"`
	Height  int      `xml:"height,attr"`
}

type TileMapObjectGroup

type TileMapObjectGroup struct {
	XMLName    xml.Name        `xml:"objectgroup"`
	Id         int             `xml:"id,attr"`
	Name       string          `xml:"name,attr"`
	Properties []Property      `xml:"properties>property"`
	Objects    []TileMapObject `xml:"object"`
	Tilemap    *TileMap
}

func (*TileMapObjectGroup) Draw

func (objectGroup *TileMapObjectGroup) Draw(screen *ebiten.Image)

func (*TileMapObjectGroup) GetId

func (o *TileMapObjectGroup) GetId() string

func (*TileMapObjectGroup) UnmarshalXML

func (o *TileMapObjectGroup) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error

type TileSet

type TileSet struct {
	XMLName      xml.Name `xml:"tileset"`
	Version      string   `xml:"version,attr"`
	TiledVersion string   `xml:"tiledversion,attr"`
	Name         string   `xml:"name,attr"`
	Path         string
	TileWidth    int             `xml:"tilewidth,attr"`
	TileHeight   int             `xml:"tileheight,attr"`
	TileCount    int             `xml:"tilecount,attr"`
	Columns      int             `xml:"columns,attr"`
	Image        ImageDefinition `xml:"image"`
	Properties   []Property      `xml:"properties>property"`
	Tiles        []Tile          `xml:"tile"`
}

func (*TileSet) GetTileById

func (tileSet *TileSet) GetTileById(id int) *Tile

type TileSetDefinition

type TileSetDefinition struct {
	XMLName  xml.Name `xml:"tileset"`
	FirstGID int      `xml:"firstgid,attr"`
	Source   string   `xml:"source,attr"`
	TileSet  *TileSet
}

type TileSetObject

type TileSetObject struct {
	XMLName    xml.Name    `xml:"object"`
	Id         int         `xml:"id,attr"`
	X          float64     `xml:"x,attr"`
	Y          float64     `xml:"y,attr"`
	Name       string      `xml:"name,attr"`
	Type       string      `xml:"type,attr"`
	Width      *float64    `xml:"width,attr"`
	Height     *float64    `xml:"height,attr"`
	Visible    *bool       `xml:"visible,attr"`
	IsPoint    *NodeExists `xml:"point"`
	IsEllipse  *NodeExists `xml:"ellipse"`
	Polygon    *Polygon    `xml:"polygon"`
	Properties []Property  `xml:"properties>property"`
}

func (*TileSetObject) GetType

func (o *TileSetObject) GetType() TileSetObjectType

type TileSetObjectGroup

type TileSetObjectGroup struct {
	XMLName    xml.Name        `xml:"objectgroup"`
	Id         int             `xml:"id,attr"`
	DrawOrder  string          `xml:"draworder,attr"`
	Properties []Property      `xml:"properties>property"`
	Objects    []TileSetObject `xml:"object"`
}

type TileSetObjectType

type TileSetObjectType int
const (
	POINT TileSetObjectType = iota
	ELLIPSE
	POLYGON
	RECTANGLE
)

Jump to

Keyboard shortcuts

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