kemokemo / ebiten-gauge

a gauge parts for ebitengine games

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ebiten Gauge

This is a package for displaying a simple gauge.
It is intended to be used in games that use ebiten.

sample

How to use

First of all, you need create an instance of the gauge.

// position
x := 50
y := 80
// gauge's max value
max := 100

// create gauge instance
gauge1 := gauge.NewGauge(x, y, max)

// If you want to specify the dot's color of this gauge,
// you can use NewGaugeWithColor function
// 
gaugeGray := gauge.NewGaugeWithColor(x, y, max, color.RGBA{R: 80, G: 80, B: 80, A: 255})

// If you want to specify scale for gauge,
// you can use NewGaugeWithScale function
// gaugeGray := gauge.NewGaugeWithScale(x, y, max, color.RGBA{R: 80, G: 80, B: 80, A: 255}, 2.0)

In standard operation, the dot of gauge blinks when the current value reaches the MAX value. Blinking can be turned off for gauges that do not require blinking or are mainly used for decreasing values.

gauge1 := gauge.NewGauge(x, y, max)

// turn off blinking
gauge1.SetBlink(false)

Second, you updates on the ebiten.game's update function. Please call Update function with the current value for the gauge.

func (g *Game) Update() error {
 // currentValue is updated by your game logic

 g.gauge1.Update(float64(currentValue))

 // some logic...
 return nil
}

Third, draw the gauge on the Draw function of your game.

func (g *Game) Draw(screen *ebiten.Image) {
 // draw some other items

 g.gauge1.Draw(screen)

 // draw some other items
}

That's all!

Please check the sample app for more detail.

Basic

License

Apache-2.0 License

Author

kemokemo

About

a gauge parts for ebitengine games

License:Apache License 2.0


Languages

Language:Go 100.0%