API Quick Reference

A compact listing of every public function, type, and constant in the GoSprite64 API.

Core

SymbolDescription
Run(g Game)Starts the game loop with fixed-step timing at 60 FPS
Game (interface)Implement Init(), Update(), Draw() to define your game
TargetFPS (var, int)Target frame rate, defaults to 60
RegisterAssetFS(f cartfs.FS)Registers the embedded cartridge filesystem for asset loading
LoadFromCartridge(filename string) ([]byte, error)Reads a raw file from the cartridge filesystem

Drawing

SymbolDescription
ClearScreen()Fills the screen with Black
ClearScreenWith(c color.Color)Fills the screen with the given color
FillRect(x1, y1, x2, y2 int, c color.Color)Draws a filled rectangle (inclusive coordinates)
DrawRect(x1, y1, x2, y2 int, c color.Color)Draws a rectangle outline
DrawLine(x1, y1, x2, y2 int, c color.Color)Draws a 1-pixel line (Bresenham for diagonals)
DrawImage(src image.Image, x, y int)Draws a Go image.Image at screen coordinates
DrawWorldImage(src image.Image, worldX, worldY int, cam *Camera)Draws an image in world space, offset by camera

Colors

All 16 predefined palette colors are exported as color.Color variables:

VariableRGB
Black(0, 0, 0)
DarkBlue(29, 43, 83)
DarkPurple(126, 37, 83)
DarkGreen(0, 135, 81)
Brown(171, 82, 54)
DarkGray(95, 87, 79)
LightGray(194, 195, 199)
White(255, 241, 232)
Red(255, 0, 77)
Orange(255, 163, 0)
Yellow(255, 236, 39)
Green(0, 228, 54)
Blue(41, 173, 255)
Indigo(131, 118, 156)
Pink(255, 119, 168)
Peach(255, 204, 170)

Sprites

SymbolDescription
SpriteSheet (struct)A loaded sprite sheet containing animation frames
LoadSpriteSheet(path string) (*SpriteSheet, error)Loads a sprite sheet from the cartridge filesystem
(*SpriteSheet).FrameCount() intReturns the total number of frames
(*SpriteSheet).FrameWidth() intReturns the width of each frame in pixels
(*SpriteSheet).FrameHeight() intReturns the height of each frame in pixels
DrawSprite(sheet *SpriteSheet, frame int, x, y float32)Draws a sprite frame at screen coordinates
DrawSpriteWithOptions(sheet *SpriteSheet, frame int, x, y float32, opts DrawSpriteOptions)Draws a sprite with flip, scale, rotation, blend
DrawWorldSprite(sheet *SpriteSheet, frame int, worldX, worldY float32, cam *Camera)Draws a sprite in world space
DrawWorldSpriteWithOptions(sheet *SpriteSheet, frame int, worldX, worldY float32, cam *Camera, opts DrawSpriteOptions)World-space sprite with options
DrawSpriteOptions (struct)FlipH, FlipV, ScaleX, ScaleY, Rotation, OriginX, OriginY, Blend, Alpha
BlendMode (uint8)Blend mode enum type
BlendNoneNo blending (fastest, opaque blit)
BlendMaskedBinary alpha (pixels are fully opaque or fully transparent)
BlendAlphaPer-pixel alpha blending

Sheet & Tile

SymbolDescription
Sheet (struct)A tile sheet loaded from a bundle
SheetInfo (struct)TileWidth, TileHeight, TileCount, AtlasWidth, AtlasHeight
(*Sheet).Info() SheetInfoReturns tile dimensions and atlas size
(*Sheet).Tile(tileID uint16) image.ImageReturns the image for a single tile

Animation

SymbolDescription
AnimationSet (struct)A named collection of animation clips
AnimationClip (struct)Name, FPS, and frame indices for one clip
(*AnimationSet).Name() stringReturns the animation set's name
(*AnimationSet).Clips() []AnimationClipReturns all clips in the set
(*AnimationSet).Clip(name string) (AnimationClip, bool)Looks up a clip by name
AnimationPlayer (struct)Drives frame-by-frame playback of a clip
NewAnimationPlayer() *AnimationPlayerCreates a new player (stopped)
(*AnimationPlayer).Play(clip AnimationClip)Starts playing a clip from frame 0
(*AnimationPlayer).Pause()Pauses playback
(*AnimationPlayer).Resume()Resumes a paused player
(*AnimationPlayer).Stop()Stops playback and resets to frame 0
(*AnimationPlayer).Restart()Replays the current clip from the start
(*AnimationPlayer).SetLoop(loop bool)Enables or disables looping
(*AnimationPlayer).Advance(ticks int)Advances playback by the given number of ticks
(*AnimationPlayer).Frame() intReturns the current frame index
(*AnimationPlayer).Playing() boolTrue if the player is actively playing
(*AnimationPlayer).Done() boolTrue if playback has stopped

Fonts & Text

SymbolDescription
DrawText(str string, x, y int, c color.Color)Draws text using the built-in 8x8 font
Font (struct)Custom font with per-glyph metrics from a sprite sheet
Glyph (struct)Frame, Width, Advance, OffsetX, OffsetY
NewFont(sheet *SpriteSheet, glyphs map[rune]Glyph, lineHeight int) *FontCreates a custom font
(*Font).LineHeight() intVertical distance between baselines
(*Font).GlyphFor(r rune) (Glyph, bool)Looks up a glyph, falls back to Font.Fallback
(*Font).MeasureText(text string) (width, height int)Measures pixel size of rendered text
(*Font).DrawTextEx(text string, x, y int, align TextAlign)Draws text with alignment
(*Font).WrapText(text string, maxWidth int) stringInserts newlines to wrap text at a pixel width
FormatScore(score int, width int) stringFormats an integer with leading zeros
TextAlign (int)Horizontal alignment enum
AlignLeftLeft-aligned (default)
AlignCenterCenter-aligned
AlignRightRight-aligned

Input

SymbolDescription
IsButtonDown(button ButtonMask) boolTrue if button is held (port 0)
IsButtonJustPressed(button ButtonMask) boolTrue on the frame a button transitions to pressed (port 0)
StickPosition(deadzone float64) (float64, float64)Analog stick X/Y in [-1, 1] (port 0)
PlayerButtonDown(port int, button ButtonMask) boolPer-port button held check
PlayerButtonJustPressed(port int, button ButtonMask) boolPer-port just-pressed check
PlayerStickPosition(port int, deadzone float64) (float64, float64)Per-port analog stick
IsControllerConnected(port int) boolTrue if a controller is plugged into the given port
ConnectedControllers() intNumber of connected controllers
SetRumble(port int, enabled bool)Enables or disables the rumble pak
ButtonMask (type alias)Bitmask type for button constants
MaxControllers (const, 4)Number of controller ports

Button constants: ButtonA, ButtonB, ButtonZ, ButtonStart, ButtonDPadUp, ButtonDPadDown, ButtonDPadLeft, ButtonDPadRight, ButtonL, ButtonR, ButtonCUp, ButtonCDown, ButtonCLeft, ButtonCRight

Input Replay

SymbolDescription
FrameInput (struct)Buttons, StickX, StickY for one player/frame
ReplayData (struct)PlayerCount, FrameCount, and recorded frames
InputRecorder (struct)Records per-frame input during gameplay
NewInputRecorder(playerCount int) *InputRecorderCreates a recorder
(*InputRecorder).CaptureFrame(player int, input FrameInput)Records one frame
(*InputRecorder).Finish() *ReplayDataFinalizes recording
InputPlayer (struct)Replays recorded input
NewInputPlayer(data *ReplayData) *InputPlayerCreates a replay player
(*InputPlayer).NextFrame(player int) (FrameInput, bool)Gets next frame for a player
(*InputPlayer).Done() boolTrue when all frames consumed
(*InputPlayer).Reset()Restarts playback from the beginning
(*InputPlayer).CurrentFrame() intCurrent playback position

Audio

SymbolDescription
AudioAsset (struct)Describes a single audio asset (ID, rate, loop points, etc.)
AudioBundle (struct)Collection of audio assets with data and name resolver
RegisterAudioBundle(bundle AudioBundle)Registers audio assets before Run()
PlaySoundEffect(id sfx.ID) boolPlays a sound effect, returns true if queued
PlayMusic(id music.ID) boolStarts music playback
StopMusic()Stops the current music track
SetSoundEffectVolume(v float32)Sets SFX volume (0.0-1.0)
SetMusicVolume(v float32)Sets music volume (0.0-1.0)
DefaultAudioOutputRate (const, 48000)DAC output rate in Hz

Tile Scenes

SymbolDescription
Bundle (struct)A loaded asset bundle containing sheets, maps, and animations
OpenBundle(path string) (*Bundle, error)Opens a bundle from the cartridge filesystem
(*Bundle).LoadSheet(name string) (*Sheet, error)Loads a named sheet from the bundle
(*Bundle).LoadMap(name string) (*Map, error)Loads a named map from the bundle
(*Bundle).LoadAnimation(name string) (*AnimationSet, error)Loads a named animation set
Scene (struct)A fully loaded tile scene with map, sheets, and animations
LoadScene(bundle *Bundle) (*Scene, error)Loads all assets from a bundle into a renderable scene
(*Scene).Draw(cam *Camera)Renders all visible layers with the given camera
(*Scene).Map() *MapReturns the scene's map
(*Scene).Sheet(index int) *SheetReturns a sheet by index
(*Scene).SheetByID(id uint16) *SheetReturns a sheet by 1-based ID
(*Scene).SheetCount() intNumber of sheets in the scene
(*Scene).Animation(index int) *AnimationSetReturns an animation by index
(*Scene).AnimationByName(name string) *AnimationSetLooks up an animation set by name
(*Scene).AnimationCount() intNumber of animation sets
(*Scene).LayerSheet(layer int) (*Sheet, bool)Returns the sheet assigned to a layer
(*Scene).LayerAssets(layer int) (MapLayerInfo, *Sheet, bool)Returns layer info and sheet together
(*Scene).LayerSheetInfo(layer int) (SheetInfo, bool)Returns the SheetInfo for a layer
(*Scene).Stats() RuntimeStatsReturns rendering statistics (allocation-free)
Map (struct)Tile map with layers of cell data
MapLayerInfo (struct)SheetID, NonZeroTiles
(*Map).Width() intMap width in tiles
(*Map).Height() intMap height in tiles
(*Map).TileWidth() intWidth of each tile in pixels
(*Map).TileHeight() intHeight of each tile in pixels
(*Map).PixelWidth() intTotal map width in pixels
(*Map).PixelHeight() intTotal map height in pixels
(*Map).LayerCount() intNumber of layers
(*Map).LayerInfo(layer int) (MapLayerInfo, bool)Returns cached info for a layer (O(1))
(*Map).LayerSheetID(layer int) (uint16, bool)Returns the sheet ID for a layer
(*Map).TileAt(layer, x, y int) (uint16, bool)Returns the tile ID at a grid position
RuntimeStats (struct)SheetRAMBytes, MapRAMBytes, CachedChunks, VisibleTiles, SheetCount, LayerCount, UploadCount

Game Systems

SymbolDescription
GameState (interface)Enter, Update, Draw, Exit for screen management
StateMachine (struct)Stack-based game state manager
NewStateMachine(initial GameState) *StateMachineCreates a state machine
(*StateMachine).Init()Triggers Enter() on the initial state
(*StateMachine).Update()Delegates to the top state's Update()
(*StateMachine).Draw()Delegates to the top state's Draw()
(*StateMachine).Switch(state GameState)Replaces the top state
(*StateMachine).Push(state GameState)Overlays a new state (for pause menus, dialogs)
(*StateMachine).Pop()Removes the top state
(*StateMachine).Current() GameStateReturns the active state
(*StateMachine).Depth() intNumber of states on the stack
MenuItem (struct)Label, Disabled, OnConfirm callback
Menu (struct)D-pad-navigated list with cursor tracking
NewMenu(items []MenuItem) *MenuCreates a menu
(*Menu).HandleInput() boolReads D-pad/A button, returns true on confirm
(*Menu).Draw()Renders the menu using DrawText
(*Menu).MoveUp()Moves cursor up (skips disabled items)
(*Menu).MoveDown()Moves cursor down (skips disabled items)
(*Menu).Confirm()Triggers the selected item's callback
(*Menu).Cursor() intReturns the cursor position
(*Menu).SetCursor(index int)Sets the cursor position
(*Menu).Selected() MenuItemReturns the highlighted item
(*Menu).Count() intNumber of items
Timer (struct)Counts down a fixed number of frames
NewTimer(durationFrames int) *TimerCreates a one-shot timer
(*Timer).Tick() boolAdvances one frame, returns true when it finishes
(*Timer).Done() boolTrue when the timer has expired
(*Timer).Progress() float32Elapsed/duration ratio (0-1)
(*Timer).Elapsed() intFrames elapsed
(*Timer).Remaining() intFrames left
(*Timer).Duration() intTotal frame count
(*Timer).Reset()Restarts with the same duration
(*Timer).ResetWith(durationFrames int)Restarts with a new duration
RepeatingTimer (struct)Triggers at a fixed interval, counts triggers
NewRepeatingTimer(intervalFrames int) *RepeatingTimerCreates a repeating timer
(*RepeatingTimer).Tick() boolAdvances one frame, returns true on trigger
(*RepeatingTimer).Count() intNumber of times triggered
(*RepeatingTimer).Reset()Clears elapsed time and count

Parallax

SymbolDescription
ParallaxLayer (struct)SpeedX, SpeedY scroll multipliers
(ParallaxLayer).Offset(cameraX, cameraY int) (int, int)Computes the layer offset for a camera position
ParallaxConfig (struct)Holds a slice of ParallaxLayer
NewParallaxConfig(speeds ...ParallaxLayer) ParallaxConfigCreates a parallax config from layer speeds
(ParallaxConfig).LayerOffset(layer, cameraX, cameraY int) (int, int)Returns the scroll offset for a specific layer

Transitions

SymbolDescription
TransitionStyle (int)Enum for transition types
FadeToBlackScreen fades to black
FadeFromBlackScreen fades in from black
Transition (struct)Style, Duration, active state
StartTransition(style TransitionStyle, durationFrames int) *TransitionBegins a screen transition
(*Transition).Advance()Advances the transition by one frame
(*Transition).Done() boolTrue when the transition has completed
(*Transition).Active() boolTrue while the transition is running
(*Transition).Stop()Cancels the transition
(*Transition).Draw()Renders the transition overlay

Draw Regions

SymbolDescription
DrawRegion (struct)X, Y, W, H defining a sub-rectangle of the screen
(DrawRegion).Active() boolTrue if the region restricts drawing
(DrawRegion).Offset(x, y int) (int, int)Translates local coordinates to screen space
(DrawRegion).Clip(x1, y1, x2, y2 int) (int, int, int, int, bool)Clips a rectangle to the region, returns false if outside
(DrawRegion).ContainsPoint(x, y int) boolTrue if a local point is inside the region
SetDrawRegion(x, y, w, h int)Restricts drawing to a screen sub-rectangle (nestable)
ResetDrawRegion()Removes the most recent draw region

Camera

SymbolDescription
Camera (struct)X, Y, Width, Height, Zoom, FollowTarget, FollowSpeed, Bounds
(*Camera).EffectiveZoom() float32Returns Zoom, defaulting to 1.0 if unset
(*Camera).WorldToScreen(worldX, worldY float32) (float32, float32)Converts world coordinates to screen coordinates
(*Camera).UpdateFollow()Moves the camera toward FollowTarget with smooth lerp
(*Camera).ClampToBounds()Restricts camera position to stay within Bounds
(*Camera).AddTrauma(amount float32)Adds screen shake intensity (0-1)
(*Camera).UpdateShake()Decays trauma each frame
(*Camera).ShakeOffset() (int, int)Returns the current frame's shake displacement

Sub-Packages

GoSprite64 also provides these sub-packages for specialized functionality:

PackageImport PathPurpose
math2dgosprite64/math2d2D vectors, rectangles, collision, easing, grid utilities, random numbers
math3dgosprite64/math3d3D vectors, 4x4 matrices, viewport projection
savegosprite64/saveEEPROM, SRAM, and FlashRAM save data
gfxgosprite64/gfxLow-level display list construction and execution
dmagosprite64/dmaDMA transfer helpers, MIO0 decompression, memory pool
rspqgosprite64/rspqRSP task queue, microcode loading, OS task submission
n64osgosprite64/n64osN64 OS primitives: scheduler, timers, events, messages
scene3dgosprite64/scene3d3D scene graph, camera, mesh, LOD, triangle rendering
audio/sfxgosprite64/audio/sfxSound effect ID type
audio/musicgosprite64/audio/musicMusic track ID type
audio/bankgosprite64/audio/bankInstrument bank loading
audio/sequencegosprite64/audio/sequenceSequence player for MIDI-style playback