tilemap

command
v0.0.0-...-8fc0beb Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2016 License: MIT Imports: 5 Imported by: 0

README

TileMap Demo

What does it do?

It demonstrates how one can load and render a TMX file created from the TileMap Editor

What are important aspects of the code?

These lines are key in this demo:

  • 'resource, err := engo.Files.Resource("example.tmx")' to retrieve the resource
  • 'tmxResource := resource.(common.TMXResource)'to cast the resource to a tmx resource
  • 'levelData := tmxResource.Level' to retrieve the level from the tmx resource

Add render and space components to each tile in each tile layer

    tileComponents := make([]*Tile, 0)

    for _, tileLayer := range levelData.TileLayers {
        for _, tileElement := range tileLayer.Tiles {
            if tileElement.Image != nil {

                tile := &Tile{BasicEntity: ecs.NewBasic()}
                tile.RenderComponent = common.RenderComponent{
                    Drawable: tileElement,
                    Scale:    engo.Point{1, 1},
                }
                tile.SpaceComponent = common.SpaceComponent{
                    Position: tileElement.Point,
                    Width:    0,
                    Height:   0,
                }

                tileComponents = append(tileComponents, tile)
            }
        }
    }

Add render and space components to each image in each image layer

    for _, imageLayer := range levelData.ImageLayers {
        for _, imageElement := range imageLayer.Images {
            if imageElement.Image != nil {
                tile := &Tile{BasicEntity: ecs.NewBasic()}
                tile.RenderComponent = common.RenderComponent{
                    Drawable: imageElement,
                    Scale:    engo.Point{1, 1},
                }
                tile.SpaceComponent = common.SpaceComponent{
                    Position: imageElement.Point,
                    Width:    0,
                    Height:   0,
                }

                tileComponents = append(tileComponents, tile)
            }
        }
    }

Access object layers and do something with its regular and polyline objects

    // Access Object Layers
    for _, objectLayer := range levelData.ObjectLayers {
        log.Println("This object layer is called " + objectLayer.Name)
        // Do something with every regular Object
        for _, object := range objectLayer.Objects {
            log.Println("This object is called " + object.Name)
        }

        // Do something with every polyline Object
        for _, polylineObject := range objectLayer.PolyObjects {
            log.Println("This object is called " + polylineObject.Name)
        }
    }

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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