gauge

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlinkingOp added in v0.0.3

type BlinkingOp struct {
	Op *ebiten.DrawImageOptions
	// contains filtered or unexported fields
}

DrawImageOption extension to make an element blink.

Set the blinking speed with SetInterval and update the blinking state with Update while drawing the element using the property Op.

func NewBlinkingOp added in v0.0.3

func NewBlinkingOp(dotClr color.Color) *BlinkingOp

func (*BlinkingOp) Clear added in v0.0.3

func (b *BlinkingOp) Clear()

Clear clears internal values except the interval value. If you want to change the blinking interval, please use SetInterval method.

func (*BlinkingOp) SetInterval added in v0.0.4

func (b *BlinkingOp) SetInterval(interval int)

SetInterval sets the interval of blinking. Larger values will cause it to blink more slowly.

func (*BlinkingOp) Update added in v0.0.3

func (b *BlinkingOp) Update()

Update updates the internal values to blink.

type Gauge

type Gauge struct {
	// contains filtered or unexported fields
}

func NewGauge

func NewGauge(x, y int, max float64) *Gauge

NewGauge generates a new gauge ui component.

x,y: position
max: gauge's max value

func NewGaugeWithColor

func NewGaugeWithColor(x, y int, max float64, dotClr color.Color) *Gauge

NewGauge generates a new gauge ui component with specified colors.

x,y: position
max: gauge's max value
dotClr: dot's color
bkClr: background color

func NewGaugeWithScale added in v0.0.5

func NewGaugeWithScale(x, y int, max float64, dotClr color.Color, scale float64) *Gauge

func (*Gauge) Draw

func (g *Gauge) Draw(screen *ebiten.Image)
func (g *Gauge) SetBlink(blink bool)

func (*Gauge) SetBlinkInterval added in v0.0.4

func (g *Gauge) SetBlinkInterval(interval int)

func (*Gauge) Update

func (g *Gauge) Update(v float64)

Update updates the gauge appearance with the v value of arg.

Directories

Path Synopsis
cmd module

Jump to

Keyboard shortcuts

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