Skip to content

martinlindhe/gameui

Repository files navigation

About

GoDoc Travis-CI codecov.io

A game UI for golang with boilerplate to run with ebiten.

Example usage

package main

import "github.com/martinlindhe/gameui"

const (
    width, height = 320, 200
    fontName      = "_resources/font/open_dyslexic/OpenDyslexic3-Regular.ttf"
)

var (
    gui       = ui.New(width, height)
    font12, _ = ui.NewFont(fontName, 12, 72, ui.White)
)

func main() {
    // add a text element
    text := ui.NewText(font12).SetText("hello")
    text.Position = ui.Point{X: width/2 - text.GetWidth()/2, Y: height / 3}
    gui.AddComponent(text)

    if err := gui.Update(); err != nil {
        return err
    }

    // get a image.Image
    img := gui.Render()
}

Full example using ebiten:

go get github.com/martinlindhe/gameui
cd $GOPATH/src/github.com/martinlindhe/gameui
go run examples/tooltip/main.go

See the examples folder for more examples

License

Under MIT