Settings & Lifecycle

Cartridge interface

type Cartridge interface {
	Init()   // Called once at the start.
	Update() // Called every frame for logic.
	Draw()   // Called every frame for drawing.
}

Your game struct must implement this interface. See The Game Loop.

InsertGame(cartridge Cartridge)

Registers your game implementation with PIGO8. Call this before Play()/PlayGameWith() - skipping it doesn't error, but runs a no-op cartridge with empty Init/Update/Draw methods (a blank window), so your game logic never runs.

Play()

Runs the console with default settings, using the cartridge registered via InsertGame. Equivalent to PlayGameWith(NewSettings()).

PlayGameWith(settings *Settings)

Runs the console with custom settings.

NewSettings() *Settings

Creates a Settings object populated with defaults.

Settings struct

FieldTypeDefaultDescription
ScaleFactorint4Integer window scaling factor.
WindowTitlestring"PIGO-8 Game"Window title bar text.
TargetFPSint30Target ticks per second.
ScreenWidthint128Logical screen width.
ScreenHeightint128Logical screen height.
MultiplayerboolfalseEnable multiplayer networking.
FullscreenboolfalseStart in fullscreen.
ColorSpaceebiten.ColorSpacedefaultRendering color space.
DisableHiDPIbooltrueDisable HiDPI scaling.
SpriteImageCacheSizeint256Max cached transparent sprite images.
SpritePixelCacheSizeint256Max cached sprite pixel data entries.
SsprCacheSizeint128Max cached Sspr source regions.
MapCacheEnabledbooltrueEnable map tile caching.
EnableFrameStatsboolfalseEnable frame-level performance statistics.

Example:

settings := p8.NewSettings()
settings.WindowTitle = "My Game"
settings.ScaleFactor = 4
settings.TargetFPS = 60
settings.ScreenWidth = 160
settings.ScreenHeight = 144

p8.InsertGame(&game{})
p8.PlayGameWith(settings)

SetMapCacheEnabled(enabled bool)

Enables or disables the composited-image cache used by Map(). Mirrors Settings.MapCacheEnabled at startup, but can also be called at runtime - useful for a map that's regenerated every frame (e.g. procedural generation), where a stale cache would otherwise show outdated tiles.

Example:

p8.SetMapCacheEnabled(false) // always redraw the map fresh, e.g. before a procedural rebuild
p8.Map()
p8.SetMapCacheEnabled(true) // re-enable for normal scrolling performance

See also: Settings, The Game Loop