DebugUI v0.1.0 がリリースされました

Hajime Hoshi
2025-04-05

DebugUI は、Ebitengine のデバッグ用 UI ライブラリです。ゲームを開発していると、デバッグ用の UI が必要になることがあります。例えば、 FPS や TPS を表示したり、ゲーム内パラメータを動的に変更したりなどです。そのためにクリックの処理やキーボードの処理を書いたり、 UI 描画のコードを書いたりするのは面倒ですね。 DebugUI は簡単に使えるデバッグ用 UI を提供します。

DebugUI を使用すると、パラメータが多量にある操作もスッキリと取り扱うことができます。

DebugUI 使用前

DebugUI 使用前

DebugUI 使用後

DebugUI 使用後

DebugUI は Immediate Mode な API です。例えば 1 個のウィンドウと 1 個のボタンを表示するコードは次のようになります。

package main

import (
	"fmt"
	"image"
	"os"

	"github.com/ebitengine/debugui"
	"github.com/hajimehoshi/ebiten/v2"
	"github.com/hajimehoshi/ebiten/v2/ebitenutil"
)

type Game struct {
	debugui debugui.DebugUI

	count int
}

func (g *Game) Update() error {
	if _, err := g.debugui.Update(func(ctx *debugui.Context) error {
		ctx.Window("Test", image.Rect(60, 60, 160, 120), func(layout debugui.ContainerLayout) {
			ctx.Button("Button").On(func() {
				g.count++
			})
		})
		return nil
	}); err != nil {
		return err
	}
	return nil
}

func (g *Game) Draw(screen *ebiten.Image) {
	g.debugui.Draw(screen)
	ebitenutil.DebugPrint(screen, fmt.Sprintf("Count: %d", g.count))
}

func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int) {
	return outsideWidth, outsideHeight
}

func main() {
	if err := ebiten.RunGame(&Game{}); err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
}

これを実行すると次のような画面になります。

ボタン 1 つの DebugUI 使用例

ボタン 1 つの DebugUI 使用例

ポイントは次のとおりです。

もう少し複雑な例は、 Ebitengine のサンプルDebugUI のサンプルなどをご覧ください。

DebugUI はまだバージョン 0 なので、 API の破壊的変更が将来行われる可能性があります。ご注意ください。