game-loop
Skill1 starsChanged 2 months agoMITView on GitHub
Ebitengine game loop, ebiten.Game interface, TPS/FPS, window management, RunGameOptions.
In this repository30 other files it gives its agents.
- arch-linux-cachyosSkill
- arch-linux-triageSkill
- bash-defensive-patternsSkill
- bash-linuxSkill
- bash-scriptingSkill
- beansSkill
- context7Skill
- docker-compose-setupSkill
- audioSkill
- deploymentSkill
- ecsSkill
- inputSkill
- physicsSkill
- renderingSkill
- resourcesSkill
- ebitenSkill
- geminiSkill
- go-browser-testsSkill
- go-devSkill
- go-fluent-testingSkill
- go-htmx-frontendSkill
- go-setupSkill
- interactive-browser-testingSkill
- keep-on-goingSkill
- mcpcSkill
- minimaxSkill
- pixellabSkill
- playwright-mcpSkill
- public-repo-maturitySkill
- searxngSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 17
Every Ebitengine game implements three methods:
- Distinctive: line 30
All game logic goes here: movement, collision, AI, state transitions
- Distinctive: line 37
All rendering goes here: draw images, shapes, text
- Distinctive: line 124
When you want Update and Draw to be 1:1
- Distinctive: line 125
When frame timing matters more than fixed timestep
- Distinctive: line 236
Use this skill only when the task clearly matches the scope described above.
- Distinctive: line 237
Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Distinctive: line 238
Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Game Loop
The
ebiten.Gameinterface and loop lifecycle.
The Game Interface
Every Ebitengine game implements three methods:
type Game interface {
Update() error
Draw(screen *ebiten.Image)
Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)
}Update() error
- Called once per tick (1/60s by default, configurable via
ebiten.SetTPS()) - All game logic goes here: movement, collision, AI, state transitions
- Return
nilto continue, return error to exit - Return
ebiten.Terminationfor clean exit without error message
Draw(screen *ebiten.Image)
- Called once per frame (tied to display refresh rate)
- All rendering goes here: draw images, shapes, text
- Never modify game state in Draw() — it may be called at different rates than Update()
- The
screenparameter is the final render target
Layout(outsideWidth, outsideHeight int) (int, int)
- Returns the logical screen size in pixels
- Engine auto-scales logical screen to window/monitor size
- Return fixed size for pixel-perfect rendering (e.g.,
return 320, 240) - Return
outsideWidth, outsideHeightfor dynamic/responsive sizing
Starting the Game
func main() {
ebiten.SetWindowSize(640, 480)
ebiten.SetWindowTitle("My Game")
ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
ebiten.SetFPSMode(ebiten.FPSModeVsyncOn)
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
}
}RunGameOptions (v2.4+)
opts := &ebiten.RunGameOptions{
GraphicsLibrary: ebiten.GraphicsLibraryOpenGL,
InitUnfocused: false,
ScreenClearedEveryFrame: true,
SkipTaskbar: false,
}
ebiten.RunGameWithOptions(&Game{}, opts)Window Configuration
| Function | Purpose |
SetWindowSize(w, h int) | Window size in device-independent pixels |
SetWindowTitle(title string) | Window title |
SetWindowResizingMode(mode) | WindowResizingModeDisabled, WindowResizingModeOnlyFullscreenEnabled, WindowResizingModeEnabled |
SetWindowDecorated(decorated bool) | Show/hide title bar |
SetWindowPosition(x, y int) | Window position |
SetWindowFloating(float bool) | Keep window on top |
SetWindowMousePassthrough(on bool) | Click-through window |
SetFullscreen(fullscreen bool) | Toggle fullscreen |
SetFPSMode(mode) | FPSModeVsyncOn (default), FPSModeVsyncOffMaximum, FPSModeVsyncOffMinimum |
SetTPS(tps int) | Ticks per second (default 60) |
SetScreenClearedEveryFrame(cleared bool) | Auto-clear screen before Draw |
SetScreenFilterEnabled(enabled bool) | Enable/disable screen scaling filter |
SetVsyncEnabled(enabled bool) | VSync control |
Read State
| Function | Returns |
WindowSize() | (w, h int) |
IsFullscreen() | bool |
IsWindowDecorated() | bool |
WindowPosition() | (x, y int) |
CurrentFPS() | float64 |
CurrentTPS() | float64 |
ActualFPS() | float64 |
ActualTPS() | float64 |
IsFocused() | bool |
IsScreenTransparent() | bool |
TPS Modes
ebiten.SetTPS(60) // Fixed 60 ticks/sec
ebiten.SetTPS(30) // Fixed 30 ticks/sec
ebiten.SetTPS(ebiten.SyncWithFPS) // Update called every frame (decoupled)When to use SyncWithFPS
- When you want Update and Draw to be 1:1
- When frame timing matters more than fixed timestep
- Note: game logic becomes frame-rate dependent (less deterministic)
Game State Pattern
type Game struct {
state GameState
player *Player
level *Level
camera *Camera
}
type GameState int
const (
StateTitle GameState = iota
StatePlaying
StatePaused
StateGameOver
)
func (g *Game) Update() error {
switch g.state {
case StateTitle:
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
g.state = StatePlaying
}
case StatePlaying:
g.player.Update()
g.level.Update()
g.camera.Follow(g.player.Position())
case StatePaused:
if inpututil.IsKeyJustPressed(ebiten.KeyEscape) {
g.state = StatePlaying
}
case StateGameOver:
if inpututil.IsKeyJustPressed(ebiten.KeyEnter) {
g.reset()
g.state = StateTitle
}
}
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
switch g.state {
case StateTitle:
// draw title
case StatePlaying, StatePaused:
g.camera.Draw(screen, g.level, g.player)
case StateGameOver:
// draw game over
}
}Scene Management
For larger games, use a scene manager instead of switch/case:
type Scene interface {
Update() error
Draw(screen *ebiten.Image)
Layout(w, h int) (int, int)
}Clean Exit
func (g *Game) Update() error {
if ebiten.IsKeyPressed(ebiten.KeyEscape) {
return ebiten.Termination
}
return nil
}Anti-Patterns
| Don't | Do |
Modify state in Draw() | All state changes in Update() only |
Allocate in Update()/Draw() hot paths | Pre-allocate in constructor |
Ignore Layout() consistency | Return same logical size unless intentionally dynamic |
Use log.Fatal() in Update | Return error to let RunGame handle it |
Block in Update() | Keep Update non-blocking, < 16ms per tick |
Remember: Update is logic. Draw is rendering. Never mix them.
When to Use
This skill is applicable when implementing or modifying the Ebitengine game loop, window configuration, or game state management.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

