assets

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package assets loads and caches game content: images, sound effects and music.

Index

Constants

View Source
const SampleRate = 48000

SampleRate is the audio pipeline rate every stream is decoded to.

Variables

This section is empty.

Functions

func ReadFile added in v0.2.0

func ReadFile(path string) ([]byte, error)

ReadFile reads an asset from the configured filesystem, or from disk when none is set. Paths always use forward slashes in fs.FS.

func SetFS added in v0.2.0

func SetFS(f fs.FS)

SetFS routes all asset loading (sprites, sounds, music, fonts) through an embedded or custom filesystem instead of the disk.

Types

type Cache

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

Cache loads and memoizes content by file path. Each Game owns one, so the same file is decoded and uploaded to the GPU only once.

func NewCache

func NewCache() *Cache

func (*Cache) Image

func (c *Cache) Image(path string) *ebiten.Image

Image returns the cached image for a path, loading it on first use. It panics with a clear message on a missing or broken file: a game with a missing sprite is a programming bug, not a runtime condition.

func (*Cache) PlayMusic

func (c *Cache) PlayMusic(path string) *audio.Player

PlayMusic starts a path looping forever and returns the player, so the caller can stop it on scene switches.

func (*Cache) PlaySound

func (c *Cache) PlaySound(path string)

PlaySound plays a short effect, fire and forget. The decoded PCM is cached by path, so repeated plays are allocation-cheap.

Jump to

Keyboard shortcuts

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