sfx

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExportConstants

func ExportConstants() map[string]string

ExportConstants is used to export all currently loaded SFX, in a format that can be used to generate go constants.

func Load

func Load(fileSystem vfs.Opener) error

Load loads sound effects from a virtual filesystem. At the root of the filesystem there must be a "sfx.json" file, which references any files to be loaded

func LoadFolder

func LoadFolder(folder string) error

LoadFolder loads sound effects from a regular folder. See Load for more information.

Types

type Id

type Id string

Id is used to identify a specific sound effect Use Play to play the sounds after loading them

func (Id) Play

func (id Id) Play() bool

func (Id) PlayFadeIn

func (id Id) PlayFadeIn(fadeIn time.Duration) bool

func (Id) PlayRandomFadeIn

func (id Id) PlayRandomFadeIn(maxFadeIn time.Duration) bool

type Scheduler

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

Scheduler lets you register sounds that should play in the future.

If you are making a simulation game, the time is likely virtual, and this lets you use any time notion. If you use real time, just pass time.Now().Seconds() as the time.

Scheduler can be used to schedule sounds to match timed animations, without needing to worry about executing it at exactly the right time.

Remember to call Scheduler.Process() from your game loop.

func NewScheduler

func NewScheduler() *Scheduler

func (*Scheduler) Clear

func (fs *Scheduler) Clear()

func (*Scheduler) PlaySoundEffectAt

func (fs *Scheduler) PlaySoundEffectAt(id Id, at float64)

func (*Scheduler) PlaySoundEffectAtFadeIn

func (fs *Scheduler) PlaySoundEffectAtFadeIn(id Id, at float64, fadeIn time.Duration)

func (*Scheduler) PlaySoundEffectAtRandomFadeIn

func (fs *Scheduler) PlaySoundEffectAtRandomFadeIn(id Id, at float64, maxFadeInMilliSeconds int)

func (*Scheduler) Process

func (fs *Scheduler) Process(now float64)

type Sfx

type Sfx struct {
	Id           Id
	Volume       float32
	ThrottlingMs int
	Variations   []*SfxVariant
	DebugMode    bool
	// contains filtered or unexported fields
}

type SfxVariant

type SfxVariant struct {
	Path         string
	Probability  float64
	Volume       float32
	ThrottlingMs int
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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