|
1 | 1 | # go-tiled |
2 | 2 |
|
3 | | -[](https://pkg.go.dev/github.com/lafriks/go-tiled?tab=doc) |
4 | | -[](https://cloud.drone.io/lafriks/go-tiled) |
| 3 | +[](https://pkg.go.dev/github.com/lafriks/go-tiled) |
| 4 | +[](https://cloud.drone.io/lafriks/go-tiled) |
5 | 5 |
|
6 | 6 | Go library to parse Tiled map editor file format (TMX) and render map to image. Currently supports only orthogonal rendering out-of-the-box. |
7 | 7 |
|
8 | 8 | ## Installing |
9 | 9 |
|
10 | | - $ go get github.com/lafriks/go-tiled |
| 10 | +```sh |
| 11 | +go get github.com/lafriks/go-tiled |
| 12 | +``` |
11 | 13 |
|
12 | 14 | You can use `go get -u` to update the package. You can also just import and start using the package directly if you're using Go modules, and Go will then download the package on first compilation. |
13 | 15 |
|
14 | | -## Basic Usage: |
| 16 | +## Basic Usage |
15 | 17 |
|
16 | 18 | ```go |
17 | 19 | package main |
18 | 20 |
|
19 | 21 | import ( |
20 | | - "fmt" |
21 | | - "os" |
| 22 | + "fmt" |
| 23 | + "os" |
22 | 24 |
|
23 | | - "github.com/lafriks/go-tiled" |
24 | | - "github.com/lafriks/go-tiled/render" |
| 25 | + "github.com/lafriks/go-tiled" |
| 26 | + "github.com/lafriks/go-tiled/render" |
25 | 27 | ) |
26 | 28 |
|
27 | 29 | const mapPath = "maps/map.tmx" // Path to your Tiled Map. |
28 | 30 |
|
29 | 31 | func main() { |
30 | 32 | // Parse .tmx file. |
31 | | - gameMap, err := tiled.LoadFromFile(mapPath) |
32 | | - if err != nil { |
33 | | - fmt.Printf("error parsing map: %s", err.Error() |
34 | | - os.Exit(2) |
35 | | - } |
36 | | - |
37 | | - fmt.Println(gameMap) |
38 | | - |
39 | | - // You can also render the map to an in-memory image for direct |
40 | | - // use with the default Renderer, or by making your own. |
41 | | - renderer, err := render.NewRenderer(gameMap) |
42 | | - if err != nil { |
43 | | - fmt.Printf("map unsupported for rendering: %s", err.Error() |
44 | | - os.Exit(2) |
45 | | - } |
46 | | - |
47 | | - // Render just layer 0 to the Renderer. |
48 | | - err = renderer.RenderLayer(0) |
49 | | - if err != nil { |
50 | | - fmt.Printf("layer unsupported for rendering: %s", err.Error() |
51 | | - os.Exit(2) |
52 | | - } |
53 | | - |
54 | | - // Get a reference to the Renderer's output, an image.NRGBA struct. |
55 | | - img := renderer.Result |
56 | | - |
57 | | - // Clear the render result after copying the output if separation of |
58 | | - // layers is desired. |
59 | | - renderer.Clear() |
60 | | - |
61 | | - // And so on. You can also export the image to a file by using the |
62 | | - // Renderer's Save functions. |
63 | | - |
| 33 | + gameMap, err := tiled.LoadFromFile(mapPath) |
| 34 | + if err != nil { |
| 35 | + fmt.Printf("error parsing map: %s", err.Error() |
| 36 | + os.Exit(2) |
| 37 | + } |
| 38 | + |
| 39 | + fmt.Println(gameMap) |
| 40 | + |
| 41 | + // You can also render the map to an in-memory image for direct |
| 42 | + // use with the default Renderer, or by making your own. |
| 43 | + renderer, err := render.NewRenderer(gameMap) |
| 44 | + if err != nil { |
| 45 | + fmt.Printf("map unsupported for rendering: %s", err.Error() |
| 46 | + os.Exit(2) |
| 47 | + } |
| 48 | + |
| 49 | + // Render just layer 0 to the Renderer. |
| 50 | + err = renderer.RenderLayer(0) |
| 51 | + if err != nil { |
| 52 | + fmt.Printf("layer unsupported for rendering: %s", err.Error() |
| 53 | + os.Exit(2) |
| 54 | + } |
| 55 | + |
| 56 | + // Get a reference to the Renderer's output, an image.NRGBA struct. |
| 57 | + img := renderer.Result |
| 58 | + |
| 59 | + // Clear the render result after copying the output if separation of |
| 60 | + // layers is desired. |
| 61 | + renderer.Clear() |
| 62 | + |
| 63 | + // And so on. You can also export the image to a file by using the |
| 64 | + // Renderer's Save functions. |
64 | 65 | } |
65 | | - |
66 | 66 | ``` |
67 | 67 |
|
68 | 68 | ## Documentation |
69 | 69 |
|
70 | | -For further documentation, see https://pkg.go.dev/github.com/lafriks/go-tiled or run: |
71 | | - |
72 | | - $ godoc github.com/lafriks/go-tiled |
| 70 | +For further documentation, see <https://pkg.go.dev/github.com/lafriks/go-tiled> or run: |
73 | 71 |
|
| 72 | +```sh |
| 73 | +godoc github.com/lafriks/go-tiled |
| 74 | +``` |
0 commit comments