tilemap

package
v0.0.0-...-d1ed616 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2016 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package tilemap is a TMX format Tilemap Parser and Renderer for Kaori

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(tilemap *Map) ([]byte, error)

Marshal parses the Map structure into a TMX formatted Tilemap data

func Unmarshal

func Unmarshal(data []byte, tilemap *Map) error

Unmarshal parses TMX formatted Tilemap data into a Map structure

Types

type Data

type Data struct {
	Encoding    string `xml:"encoding,attr"`
	Compression string `xml:"compression,attr"`

	Data string `xml:",chardata"`
}

Data is a structure for Layer's Tile Data

type Image

type Image struct {
	Source string `xml:"source,attr"`

	Width  int `xml:"width,attr"`
	Height int `xml:"height,attr"`
}

Image is the actual image for the spritesheet or texture

type Layer

type Layer struct {
	Parent *Map

	Name string `xml:"name,attr"`

	Width  int `xml:"width,attr"`
	Height int `xml:"height,attr"`

	Spacing int `xml:"spacing,attr"`
	Margin  int `xml:"margin,attr"`

	Data *Data `xml:"data"`

	Tiles [][]int `xml:"-"`
}

Layer is a structure for TMX Tilemap Layers

func (*Layer) Draw

func (l *Layer) Draw(renderer *sdl.Renderer, x, y int32)

Draw draws the layer to the renderer with the starting location of x and y

func (*Layer) Read

func (l *Layer) Read() error

Read parses the layer's tile data into two dimension array of integers

type Map

type Map struct {
	XMLName xml.Name `xml:"map"`

	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"`

	Tilesets []*Tileset `xml:"tileset"`

	Layers       []*Layer       `xml:"layer"`
	ObjectGroups []*ObjectGroup `xml:"objectgroup"`
}

Map is the actual TMX map structure

func (*Map) Draw

func (m *Map) Draw(renderer *sdl.Renderer, x, y int32)

Draw draws the Map with the renderer starting at the provided location

type Object

type Object struct {
	Id int `xml:"id,attr"`

	X int `xml:"x,attr"`
	Y int `xml:"y,attr"`

	Gid int `xml:"gid,attr"`

	Width  int `xml:"width,attr"`
	Height int `xml:"height,attr"`

	Polyline Polyline `xml:"polyline"`
}

Object is a tile map object It can be an ellipse, rectangle, or a polyline

type ObjectGroup

type ObjectGroup struct {
	Name    string    `xml:"name,attr"`
	Objects []*Object `xml:"object"`
}

ObjectGroup is a group of tiled map objects

type Polyline

type Polyline struct {
	Points string `xml:"points,attr"`
}

Polyline is a list of points representing a polygonal shape or line

type Tileset

type Tileset struct {
	Name string `xml:"name,attr"`

	TileWidth  int `xml:"tilewidth,attr"`
	TileHeight int `xml:"tileheight,attr"`

	TileCount int `xml:"tilecount,attr"`

	Columns int `xml:"columns,attr"`

	Spacing int `xml:"spacing,attr"`
	Margin  int `xml:"margin,attr"`

	FirstID int `xml:"firstgid,attr"`

	Image Image `xml:"image"`
}

Tileset is a set of sprites or textures for the tiled map

func (*Tileset) DrawTile

func (t *Tileset) DrawTile(renderer *sdl.Renderer, x, y int32, tile int)

DrawTile draw a specific tile to the renderer at a specific location The tile number is a continuous number starting from the tile set's first id

func (*Tileset) Free

func (t *Tileset) Free()

Free free the loaded image texture

func (*Tileset) Load

func (t *Tileset) Load(renderer *sdl.Renderer, folder string) error

Load loads the image needed as an SDL Texture via Kaori's texture package

Jump to

Keyboard shortcuts

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