shapes

command
v0.0.0-...-f174bb4 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2016 License: MIT Imports: 4 Imported by: 0

README

Shape Demo

What does it do?

It demonstrates how one can efficiently draw various shapes in solid colors (with/without border).

What are important aspects of the code?

Each shape has to have both a SpaceComponent and a RenderComponent:

triangle1 := MyShape{BasicEntity: ecs.NewBasic()}
triangle1.SpaceComponent = common.SpaceComponent{Width: 100, Height: 100}
triangle1.RenderComponent = common.RenderComponent{Drawable: common.Triangle{}, Color: color.RGBA{255, 0, 0, 255}}

In this example, the Width and Height are being used to compute the size of the shape, we set the Drawable to an instance of a common.Triangle, and set the Color to the fill color we want to use.

Finally, we add it to the RenderSystem:

for _, system := range w.Systems() {
    switch sys := system.(type) {
    case *common.RenderSystem:
        sys.Add(&triangle1.BasicEntity, &triangle1.RenderComponent, &triangle1.SpaceComponent)
    }
}

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