Documentation ¶
Overview ¶
Package tmx provides an TMX file loader specification: http://doc.mapeditor.org/reference/tmx-map-format/
Index ¶
- Constants
- type Animation
- type Canvas
- type Data
- type DataTile
- type FilesystemLocator
- type FlipMode
- type Frame
- type GID
- type Image
- type ImageCanvas
- type ImgCanvas
- type Layer
- type Map
- type Object
- type ObjectGroup
- type PolyLine
- type Polygon
- type Property
- type RelativeCanvas
- type Renderer
- type ResourceLocator
- type ResourceManager
- type Tile
- type TileFlipper
- type Tileset
- type Timer
Constants ¶
const ( //GIDHorizontalFlip for horizontal flipped tiles GIDHorizontalFlip = 0x80000000 //GIDVerticalFlip for vertical flipped tiles GIDVerticalFlip = 0x40000000 //GIDDiagonalFlip for diagonally flipped tile GIDDiagonalFlip = 0x20000000 //GIDFlips removes all flipping informations GIDFlips = GIDHorizontalFlip | GIDVerticalFlip | GIDDiagonalFlip )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Animation ¶
type Animation struct { Frames []*Frame `xml:"frame"` // contains filtered or unexported fields }
Animation references an animated tile
type Canvas ¶
type Canvas interface { FillRect(what color.Color, where image.Rectangle) Bounds() image.Rectangle }
Canvas to draw on
type Data ¶
type Data struct { Encoding string `xml:"encoding,attr"` Compression string `xml:"compression,attr"` RawData []byte `xml:",innerxml"` DataTiles []DataTile `xml:"tile"` }
Data contains raw loaded tmx data
type DataTile ¶
type DataTile struct { GID GID `xml:"gid,attr"` //HorizontalFlip true if the tile should be rendered with flip in x dir HorizontalFlip bool //VerticalFlip true if the tile should be rendered with flip in y dir VerticalFlip bool //DiagonalFlip true if it should be rendered flipped diagonally, can be combined //with `HorizontalFlip` or `VerticalFlip` DiagonalFlip bool }
DataTile datatile
type FilesystemLocator ¶
type FilesystemLocator struct { }
FilesystemLocator loads files simply from the filesystem it supports png, jpeg and non animated gifs
func (FilesystemLocator) LocateResource ¶
func (f FilesystemLocator) LocateResource(filepath string) (image.Image, error)
LocateResource to implement ResourceLocator interface
type Frame ¶
type Frame struct { //Duration is given in milliseconds Duration int64 `xml:"duration,attr"` TileID int `xml:"tileid,attr"` // contains filtered or unexported fields }
Frame is one frame of an animation
type Image ¶
type Image struct { Source string `xml:"source,attr"` Trans string `xml:"trans,attr"` Width int `xml:"width,attr"` Height int `xml:"height,attr"` }
Image refers to the image of one tile or the tileset
type ImageCanvas ¶
ImageCanvas will always draw the exact image to where
type ImgCanvas ¶
type ImgCanvas struct {
// contains filtered or unexported fields
}
ImgCanvas is a sample renderer that renders on a image.RGBA to generate snapshots
func NewImageCanvasFromMap ¶
NewImageCanvasFromMap returns an image canvas with correct bounds
type Layer ¶
type Layer struct { Name string `xml:"name,attr"` Opacity float32 `xml:"opacity,attr"` Visible *visibleValue `xml:"visible,attr"` Properties []Property `xml:"properties>property"` Data Data `xml:"data"` Width int `xml:"width,attr"` Height int `xml:"height,attr"` }
Layer represents one layer of the map.
type Map ¶
type Map struct { Version string `xml:"title,attr"` Orientation string `xml:"orientation,attr"` Width int `xml:"width,attr"` Height int `xml:"height,attr"` TileWidth int `xml:"tilewidth,attr"` TileHeight int `xml:"tileheight,attr"` BackgroundColor hexcolor `xml:"backgroundcolor,attr"` RenderOrder string `xml:"renderorder,attr"` Properties []Property `xml:"properties>property"` Tilesets []Tileset `xml:"tileset"` Layers []Layer `xml:"layer"` ObjectGroups []ObjectGroup `xml:"objectgroup"` // contains filtered or unexported fields }
Map contains map information
type Object ¶
type Object struct { Name string `xml:"name,attr"` Type string `xml:"type,attr"` X int `xml:"x,attr"` Y int `xml:"y,attr"` Width int `xml:"width,attr"` Height int `xml:"height,attr"` GID int `xml:"gid,attr"` Visible *visibleValue `xml:"visible,attr"` Polygons []Polygon `xml:"polygon"` PolyLines []PolyLine `xml:"polyline"` Properties []Property `xml:"properties>property"` }
Object is an object
type ObjectGroup ¶
type ObjectGroup struct { Name string `xml:"name,attr"` Color string `xml:"color,attr"` Opacity float32 `xml:"opacity,attr"` Visible *visibleValue `xml:"visible,attr"` Properties []Property `xml:"properties>property"` Objects []Object `xml:"object"` }
ObjectGroup is a group of objects
func (ObjectGroup) IsVisible ¶
func (o ObjectGroup) IsVisible() bool
IsVisible returns true if the object group is visible, false otherwise
type PolyLine ¶
type PolyLine struct {
Points string `xml:"points,attr"`
}
PolyLine loads a polyline from tmx
type Polygon ¶
type Polygon struct {
Points string `xml:"points,attr"`
}
Polygon loads a polygon from tmx
type RelativeCanvas ¶
type RelativeCanvas interface {
Draw(tile image.Rectangle, where image.Rectangle, f FlipMode, tileset string)
}
RelativeCanvas allows custom cropping of tiles
type Renderer ¶
Renderer renders the given Map on a provided Canvas elapsedTime in milliseconds this is necessary to update animated tiles accordingly
func NewRenderer ¶
NewRenderer lets you draw the map on a custom canvas with a default FilesystemLocator
func NewRendererWithResourceLocator ¶
func NewRendererWithResourceLocator(m Map, c Canvas, locator ResourceLocator) Renderer
NewRendererWithResourceLocator return a new renderer
func NewRendererWithResourceLocatorAndTileFlipper ¶
func NewRendererWithResourceLocatorAndTileFlipper( m Map, c Canvas, locator ResourceLocator, tf TileFlipper, ) Renderer
NewRendererWithResourceLocatorAndTileFlipper allows you to specify a custom canvas, locator and TileFlipper
type ResourceLocator ¶
ResourceLocator can be implemented to load resources differently than from filesystem
func NewLazyResourceLocator ¶
func NewLazyResourceLocator(l ResourceLocator) ResourceLocator
NewLazyResourceLocator wraps a ResourceLocator and caches results
type ResourceManager ¶
type ResourceManager interface {
UnsetResource(filepath string)
}
ResourceManager allows better memory handling and cleanup of resources
type Tile ¶
type Tile struct { ID uint32 `xml:"id,attr"` Image Image `xml:"image"` Animation *Animation `xml:"animation"` }
Tile refers to one tile in the tileset
type TileFlipper ¶
type TileFlipper interface { FlipHorizontal(image.Image) image.Image FlipVertical(image.Image) image.Image FlipDiagonal(image.Image) image.Image }
TileFlipper allows a custom implementation of flipping techniques
type Tileset ¶
type Tileset struct { FirstGID GID `xml:"firstgid,attr"` Source string `xml:"source,attr"` Name string `xml:"name,attr"` TileWidth int `xml:"tilewidth,attr"` TileHeight int `xml:"tileheight,attr"` Spacing int `xml:"spacing,attr"` Margin int `xml:"margin,attr"` Properties []Property `xml:"properties>property"` Image Image `xml:"image"` Tiles []Tile `xml:"tile"` }
Tileset entry describes a complete tileset
func (Tileset) GetFilename ¶
GetFilename returns the filename for this tileset
func (Tileset) GetNumTiles ¶
GetNumTiles returns the number of tiles of this tileset
func (Tileset) GetNumTilesX ¶
GetNumTilesX returns the number of tiles in x direction
func (Tileset) GetNumTilesY ¶
GetNumTilesY returns the number of tiles in y direction
func (Tileset) GetTileByID ¶
GetTileByID returns special tile information