Documentation ¶
Index ¶
- Variables
- type Data
- type DataTile
- type DecodedTile
- type GID
- type ID
- type Image
- type ImageLayer
- type Map
- func (m *Map) Bounds() pixel.Rect
- func (m *Map) Centre() pixel.Vec
- func (m *Map) DrawAll(target pixel.Target, clearColour color.Color, mat pixel.Matrix) error
- func (m *Map) GenerateTileObjectLayer() error
- func (m *Map) GetImageLayerByName(name string) *ImageLayer
- func (m *Map) GetObjectByName(name string) []*Object
- func (m *Map) GetObjectLayerByName(name string) *ObjectGroup
- func (m *Map) GetTileLayerByName(name string) *TileLayer
- func (m *Map) String() string
- type Object
- func (o *Object) GetEllipse() (pixel.Circle, error)
- func (o *Object) GetPoint() (pixel.Vec, error)
- func (o *Object) GetPolyLine() ([]pixel.Vec, error)
- func (o *Object) GetPolygon() ([]pixel.Vec, error)
- func (o *Object) GetRect() (pixel.Rect, error)
- func (o *Object) GetTile() (*DecodedTile, error)
- func (o *Object) GetType() ObjectType
- func (o *Object) String() string
- type ObjectGroup
- type ObjectType
- type Point
- type PolyLine
- type Polygon
- type Property
- type Tile
- type TileLayer
- type Tileset
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnknownEncoding = errors.New("tmx: invalid encoding scheme") ErrUnknownCompression = errors.New("tmx: invalid compression method") ErrInvalidDecodedDataLen = errors.New("tmx: invalid decoded data length") ErrInvalidGID = errors.New("tmx: invalid GID") ErrInvalidObjectType = errors.New("tmx: the object type requested does not match this object") ErrInvalidPointsField = errors.New("tmx: invalid points string") ErrInfiniteMap = errors.New("tmx: infinite maps are not currently supported") )
Errors which are returned from various places in the package.
var ( // NilTile is a tile with no tile set. Will be skipped over when drawing. NilTile = &DecodedTile{Nil: true} )
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct { Encoding string `xml:"encoding,attr"` Compression string `xml:"compression,attr"` RawData []byte `xml:",innerxml"` // DataTiles is only used when layer encoding is XML. DataTiles []*DataTile `xml:"tile"` }
Data is a TMX file structure holding data.
type DataTile ¶
type DataTile struct {
GID GID `xml:"gid,attr"`
}
DataTile is a tile from a data object.
type DecodedTile ¶
type DecodedTile struct { ID ID Tileset *Tileset HorizontalFlip bool VerticalFlip bool DiagonalFlip bool Nil bool // contains filtered or unexported fields }
DecodedTile is a convenience struct, which stores the decoded data from a Tile.
func (*DecodedTile) Draw ¶
func (t *DecodedTile) Draw(ind, columns, numRows int, ts *Tileset, target pixel.Target, offset pixel.Vec)
Draw will draw the tile to the target provided. This will calculate the sprite from the provided tileset and set the DecodedTiles' internal `sprite` property; this is so it is only calculated the first time.
func (*DecodedTile) IsNil ¶
func (t *DecodedTile) IsNil() bool
IsNil returns whether this tile is nil. If so, it means there is nothing set for the tile, and should be skipped in drawing.
func (DecodedTile) Position ¶
func (t DecodedTile) Position(ind int, ts *Tileset) pixel.Vec
Position returns the relative game position.
func (*DecodedTile) String ¶
func (t *DecodedTile) String() string
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"` // contains filtered or unexported fields }
Image is a TMX file structure which referencing an image file, with associated properies.
type ImageLayer ¶
type ImageLayer struct { Locked bool `xml:"locked,attr"` Name string `xml:"name,attr"` OffSetX float64 `xml:"offsetx,attr"` OffSetY float64 `xml:"offsety,attr"` Opacity float64 `xml:"opacity,attr"` Image *Image `xml:"image"` // contains filtered or unexported fields }
ImageLayer is a TMX file structure which references an image layer, with associated properties.
func (*ImageLayer) Draw ¶
Draw will draw the image layer to the target provided, shifted with the provided matrix.
func (*ImageLayer) String ¶
func (im *ImageLayer) String() string
type Map ¶
type Map struct { Version string `xml:"title,attr"` Orientation string `xml:"orientation,attr"` // Width is the number of tiles - not the width in pixels Width int `xml:"width,attr"` // Height is the number of tiles - not the height in pixels Height int `xml:"height,attr"` TileWidth int `xml:"tilewidth,attr"` TileHeight int `xml:"tileheight,attr"` Properties []*Property `xml:"properties>property"` Tilesets []*Tileset `xml:"tileset"` TileLayers []*TileLayer `xml:"layer"` ObjectGroups []*ObjectGroup `xml:"objectgroup"` Infinite bool `xml:"infinite,attr"` ImageLayers []*ImageLayer `xml:"imagelayer"` Canvas_ *pixelgl.Canvas // contains filtered or unexported fields }
Map is a TMX file structure representing the map as a whole.
func (*Map) DrawAll ¶
DrawAll will draw all tile layers and image layers to the target. Tile layers are first draw to their own `pixel.Batch`s for efficiency. All layers are drawn to a `pixel.Canvas` before being drawn to the target.
- target - The target to draw layers to. - clearColour - The colour to clear the maps' canvas before drawing. - mat - The matrix to draw the canvas to the target with.
func (*Map) GenerateTileObjectLayer ¶
GenerateTileObjectLayer will create an object layer which contains all objects as defined by individual tiles.
func (*Map) GetImageLayerByName ¶
func (m *Map) GetImageLayerByName(name string) *ImageLayer
GetImageLayerByName returns a Map's ImageLayer by its name
func (*Map) GetObjectByName ¶
GetObjectByName returns the Maps' Objects by their name
func (*Map) GetObjectLayerByName ¶
func (m *Map) GetObjectLayerByName(name string) *ObjectGroup
GetObjectLayerByName returns a Map's ObjectGroup by its name
func (*Map) GetTileLayerByName ¶
GetTileLayerByName returns a Map's TileLayer by its name
type Object ¶
type Object struct { Name string `xml:"name,attr"` Type string `xml:"type,attr"` X float64 `xml:"x,attr"` Y float64 `xml:"y,attr"` Width float64 `xml:"width,attr"` Height float64 `xml:"height,attr"` GID ID `xml:"gid,attr"` ID ID `xml:"id,attr"` Visible bool `xml:"visible,attr"` Polygon *Polygon `xml:"polygon"` PolyLine *PolyLine `xml:"polyline"` Properties []*Property `xml:"properties>property"` Ellipse *struct{} `xml:"ellipse"` Point *struct{} `xml:"point"` // contains filtered or unexported fields }
Object is a TMX file struture holding a specific Tiled object.
func (*Object) GetEllipse ¶
GetEllipse will return a pixel.Circle representation of this object relative to the map (the co-ordinates will match those as drawn in Tiled). If the object type is not `EllipseObj` this function will return `pixel.C(pixel.ZV, 0)` and an error.
Because there is no pixel geometry code for irregular ellipses, this function will average the width and height of the ellipse object from the TMX file, and return a regular circle about the centre of the ellipse.
func (*Object) GetPoint ¶
GetPoint will return a pixel.Vec representation of this object relative to the map (the co-ordinates will match those as drawn in Tiled). If the object type is not `PointObj` this function will return `pixel.ZV` and an error.
func (*Object) GetPolyLine ¶
GetPolyLine will return a pixel.Vec slice representation of this object relative to the map (the co-ordinates will match those as drawn in Tiled). If the object type is not `PolylineObj` this function will return `nil` and an error.
func (*Object) GetPolygon ¶
GetPolygon will return a pixel.Vec slice representation of this object relative to the map (the co-ordinates will match those as drawn in Tiled). If the object type is not `PolygonObj` this function will return `nil` and an error.
func (*Object) GetRect ¶
GetRect will return a pixel.Rect representation of this object relative to the map (the co-ordinates will match those as drawn in Tiled). If the object type is not `RectangleObj` this function will return `pixel.R(0, 0, 0, 0)` and an error.
func (*Object) GetTile ¶
func (o *Object) GetTile() (*DecodedTile, error)
GetTile will return the object decoded into a DecodedTile struct. If this object is not a DecodedTile, this function will return `nil` and an error.
func (*Object) GetType ¶
func (o *Object) GetType() ObjectType
GetType will return the ObjectType constant type of this object.
type ObjectGroup ¶
type ObjectGroup struct { Name string `xml:"name,attr"` Color string `xml:"color,attr"` OffSetX float64 `xml:"offsetx,attr"` OffSetY float64 `xml:"offsety,attr"` Opacity float32 `xml:"opacity,attr"` Visible bool `xml:"visible,attr"` Properties []*Property `xml:"properties>property"` Objects []*Object `xml:"object"` // contains filtered or unexported fields }
ObjectGroup is a TMX file structure holding a Tiled ObjectGroup.
func (*ObjectGroup) GetObjectByName ¶
func (og *ObjectGroup) GetObjectByName(name string) []*Object
GetObjectByName returns the ObjectGroups' Objects by their name
func (*ObjectGroup) String ¶
func (og *ObjectGroup) String() string
type ObjectType ¶
type ObjectType int
ObjectType is used to represent the types an object can be.
const ( EllipseObj ObjectType = iota PolygonObj PolylineObj RectangleObj PointObj TileObj )
These are the currently supported object types.
func (ObjectType) String ¶
func (o ObjectType) String() string
type PolyLine ¶
type PolyLine struct { Points string `xml:"points,attr"` // contains filtered or unexported fields }
PolyLine is a TMX file structure representing a Tiled Polyline.
type Polygon ¶
type Polygon struct { Points string `xml:"points,attr"` // contains filtered or unexported fields }
Polygon is a TMX file structure representing a Tiled Polygon.
type Property ¶
type Property struct { Name string `xml:"name,attr"` Value string `xml:"value,attr"` // contains filtered or unexported fields }
Property is a TMX file structure which holds a Tiled property.
type Tile ¶
type Tile struct { ID ID `xml:"id,attr"` Image *Image `xml:"image"` // ObjectGroup is set if objects have been added to individual sprites in Tiled. ObjectGroup *ObjectGroup `xml:"objectgroup,omitempty"` // contains filtered or unexported fields }
Tile is a TMX file structure which holds a Tiled tile.
type TileLayer ¶
type TileLayer struct { Name string `xml:"name,attr"` Opacity float32 `xml:"opacity,attr"` OffSetX float64 `xml:"offsetx,attr"` OffSetY float64 `xml:"offsety,attr"` Visible bool `xml:"visible,attr"` Properties []*Property `xml:"properties>property"` Data Data `xml:"data"` // DecodedTiles is the attribute you should use instead of `Data`. // Tile entry at (x,y) is obtained using l.DecodedTiles[y*map.Width+x]. DecodedTiles []*DecodedTile // Tileset is only set when the layer uses a single tileset and NilLayer is false. Tileset *Tileset // Empty should be set when all entries of the layer are NilTile. Empty bool Batch_ *pixel.Batch IsDirty bool StaticBool bool // contains filtered or unexported fields }
TileLayer is a TMX file structure which can hold any type of Tiled layer.
func (*TileLayer) Batch ¶
Batch returns the batch with the picture data from the tileset associated with this layer.
func (*TileLayer) Draw ¶
Draw will use the TileLayers' batch to draw all tiles within the TileLayer to the target.
func (*TileLayer) SetDirty ¶
SetDirty will update the TileLayers' `dirty` property. If true, this will cause the TileLayers' batch be cleared and re-drawn next time `TileLayer.Draw` is called.
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"` Tilecount int `xml:"tilecount,attr"` Columns int `xml:"columns,attr"` // contains filtered or unexported fields }
Tileset is a TMX file structure which represents a Tiled Tileset
func (Tileset) GenerateTileObjectLayer ¶
func (ts Tileset) GenerateTileObjectLayer(tileLayers []*TileLayer) ObjectGroup
GenerateTileObjectLayer will create a new ObjectGroup for the mapping of Objects to individual tiles.
func (Tileset) TileObjects ¶
func (ts Tileset) TileObjects() map[ID]*ObjectGroup
TileObjects will return all ObjectGroups contained in Tiles.