EngoEngine / engo

Engo is an open-source 2D game engine written in Go.
https://engoengine.github.io
MIT License
1.74k stars 136 forks source link

Added support for tile animations from TMX files #755

Closed eth0net closed 3 years ago

eth0net commented 3 years ago

This adds support for tile animations created in editors like Tiled and saved into the TMX files.

Currently, I have not found a good way to use the animation rate set in the editor, so that must be set when using the tile later and creating an AnimationComponent.

Here is an example of how to then implement the animation:


tiles := []*Tile{}
for idx, layer := range level.TileLayers {
    for _, tile := range layer.Tiles {
        if tile.Image == nil {
            log.Printf("Tile has no image at point: %v", tile.Point)
        }
        t := &Tile{BasicEntity: ecs.NewBasic()}
        if len(tile.Drawables) > 0 {
            t.AnimationComponent = common.NewAnimationComponent(tile.Drawables, 0.1)
            t.AnimationComponent.AddDefaultAnimation(tile.Animation)
        }
        t.RenderComponent = common.RenderComponent{
            Drawable:    tile.Image,
            Scale:       engo.Point{X: 1, Y: 1},
            StartZIndex: float32(idx),
        }
        t.SpaceComponent = common.SpaceComponent{
            Position: tile.Point,
        }
        tiles = append(tiles, t)
    }
}
coveralls commented 3 years ago

Coverage Status

Coverage increased (+0.05%) to 40.905% when pulling 4080e22c70c72869b00144d6647b879050119433 on raziel2244:master into fbe20e0b813eb5947dceb34938f972f4b61403b0 on EngoEngine:master.

Noofbiz commented 3 years ago

LGTM! Thanks for your contribution!

eth0net commented 3 years ago

Thanks for the merge!