Documentation
¶
Index ¶
- Constants
- Variables
- func Draw(renderer *sdl.Renderer, draw ...Drawable) error
- func FailOnErr(possibleErr error)
- func GetClosestDisplayModeRatio(displayIndex int, mode sdl.DisplayMode) (*sdl.DisplayMode, error)
- func LoadTextureFromMem(ren *sdl.Renderer, data []byte) (*sdl.Texture, error)
- func OpenFontFromMem(data []byte, size int) (*sdlttf.Font, error)
- func OpenFontIndexFromMem(data []byte, size, index int) (*sdlttf.Font, error)
- func RNG() *rand.Rand
- func RunLoop(stage *Stage) error
- type AssetsLoader
- func (l *AssetsLoader) Font(file string, size int, index uint) (font *sdlttf.Font, err error)
- func (l *AssetsLoader) Read(file string) ([]byte, error)
- func (l *AssetsLoader) ReadRW(file string) (*sdl.RWops, error)
- func (l *AssetsLoader) Surface(file string) (*sdl.Surface, error)
- func (l *AssetsLoader) Texture(file string) (*sdl.Texture, error)
- func (l *AssetsLoader) TextureAtlas(file string, locations map[string]sdl.Rect) (*TextureAtlas, error)
- func (l *AssetsLoader) TextureAtlasXml(file string) (*TextureAtlas, error)
- func (l *AssetsLoader) UniformTextureAtlas(file string, w, h int32, total uint8) (*TextureAtlas, error)
- type Clock
- type Drawable
- type DrawableFunc
- type FontsMap
- type Layer
- type Options
- type Scene
- type SceneActivater
- type SceneDeactivater
- type SceneDestroyer
- type SceneManager
- func (sm *SceneManager) Activate(name string) (Scene, error)
- func (sm *SceneManager) ActivationScheduled() bool
- func (sm *SceneManager) ActiveSceneName() string
- func (sm *SceneManager) Add(scene Scene)
- func (sm *SceneManager) Destroy() error
- func (sm *SceneManager) Get(name string) Scene
- func (sm *SceneManager) Has(name string) bool
- func (sm *SceneManager) Remove(name string, destroy bool) (bool, error)
- func (sm *SceneManager) ScheduleActivation(name string) error
- func (sm *SceneManager) UpdateActiveScene(scenePtr *Scene) bool
- type SplashScreen
- type Stage
- func (s *Stage) AddScene(scene Scene) error
- func (s *Stage) ClearScreen() error
- func (s *Stage) Clock() *Clock
- func (s *Stage) Context() context.Context
- func (s *Stage) Destroy()
- func (s *Stage) FHeight() float64
- func (s *Stage) FWidth() float64
- func (s *Stage) HandleKeyUpEvent(e *sdl.KeyboardEvent) error
- func (s *Stage) HandleWindowSizeChangedEvent(e *sdl.WindowEvent) error
- func (s *Stage) Height() int32
- func (s *Stage) MustAddScene(scene Scene, possibleErr error)
- func (s *Stage) PresentScreen()
- func (s *Stage) Renderer() *sdl.Renderer
- func (s *Stage) Scene() Scene
- func (s *Stage) SceneManager() *SceneManager
- func (s *Stage) SetWindowIcon(icon []byte) error
- func (s *Stage) Size() sdl.Rect
- func (s *Stage) Time() *Time
- func (s *Stage) ToggleFullscreen() (err error)
- func (s *Stage) ToggleWindowTitleFps()
- func (s *Stage) Width() int32
- func (s *Stage) Window() *sdl.Window
- type TextureAtlas
- func (ta *TextureAtlas) Destroy() error
- func (ta *TextureAtlas) GetFomIndex(i int) (TextureClip, error)
- func (ta *TextureAtlas) GetFromName(name string) (TextureClip, error)
- func (ta *TextureAtlas) HasIndex(i int) bool
- func (ta *TextureAtlas) HasName(name string) bool
- func (ta *TextureAtlas) IsUniform() bool
- func (ta *TextureAtlas) Len() int
- func (ta *TextureAtlas) Names() []string
- func (ta *TextureAtlas) Texture() *sdl.Texture
- type TextureClip
- type TexturesMap
- type Time
- func (t *Time) AvgFps() float32
- func (t *Time) ConvTicks(ticks uint32) time.Time
- func (t *Time) Elapsed() time.Duration
- func (t *Time) Fps() float32
- func (t *Time) Init() *Time
- func (t *Time) RegisterClock(clock *Clock)
- func (t *Time) SetTargetFps(targetFps uint8) *Time
- func (t *Time) String() string
- func (t *Time) Tick() float64
Constants ¶
const ( DefaultFps uint8 = 60 DefaultTimeScale float64 = 1.0 )
const QUIT quit = "QUIT"
Variables ¶
var DefaultOptions = Options{ PosX: sdl.WINDOWPOS_CENTERED, PosY: sdl.WINDOWPOS_CENTERED, WindowFlags: sdl.WINDOW_SHOWN | sdl.WINDOW_INPUT_FOCUS, FullscreenMode: 1, RendererIndex: -1, RendererFlags: sdl.RENDERER_ACCELERATED | sdl.RENDERER_PRESENTVSYNC, BgColor: color.RGBA{}, TargetFps: DefaultFps, }
var ErrInvalidTexture = stderrors.New("Invalid texture")
var FatalErrorTitle = "fatal error"
Functions ¶
func FailOnErr ¶
func FailOnErr(possibleErr error)
FailOnErr shows a simple message box and exits the program when it receives a non-nil error.
func GetClosestDisplayModeRatio ¶
func GetClosestDisplayModeRatio(displayIndex int, mode sdl.DisplayMode) (*sdl.DisplayMode, error)
func LoadTextureFromMem ¶
func OpenFontIndexFromMem ¶
Types ¶
type AssetsLoader ¶
type AssetsLoader struct { // Surfaces SurfacesMap Textures TexturesMap Fonts *FontsMap // contains filtered or unexported fields }
func NewAssetsLoader ¶
func NewAssetsLoader(fs fs.ReadFileFS, r *sdl.Renderer) *AssetsLoader
func (*AssetsLoader) TextureAtlas ¶
func (l *AssetsLoader) TextureAtlas(file string, locations map[string]sdl.Rect) (*TextureAtlas, error)
func (*AssetsLoader) TextureAtlasXml ¶
func (l *AssetsLoader) TextureAtlasXml(file string) (*TextureAtlas, error)
func (*AssetsLoader) UniformTextureAtlas ¶
func (l *AssetsLoader) UniformTextureAtlas(file string, w, h int32, total uint8) (*TextureAtlas, error)
type Clock ¶
type Clock struct { // TimeScale affects the speed of time. Its default value is 1.0. // When TimeScale < 1, time slows down. Time speeds up when TimeScale > 1. TimeScale float64 // Delta64 returns the current delta time value multiplied by TimeScale. Delta64 float64 // Delta32 is a float32 version of Delta64. Delta32 float32 // contains filtered or unexported fields }
type DrawableFunc ¶
type Options ¶
type Options struct { Context context.Context // sdl.Window options // see https://wiki.libsdl.org/SDL_CreateWindow PosX, PosY int32 WindowFlags uint32 FullscreenMode uint32 // https://wiki.libsdl.org/SDL_SetWindowFullscreen // sdl.DisplayMode options // (https://wiki.libsdl.org/SDL_DisplayMode) DisplayMode sdl.DisplayMode // sdl.Renderer options // see https://wiki.libsdl.org/SDL_CreateRenderer RendererIndex int RendererFlags uint32 BgColor color.Color // see https://wiki.libsdl.org/SDL_RenderClear // timer TargetFps uint8 // todo: DisplayMode.RefreshRate LimitFps bool WindowTitleFps bool }
type SceneActivater ¶
type SceneDeactivater ¶
type SceneDestroyer ¶
type SceneManager ¶
type SceneManager struct {
// contains filtered or unexported fields
}
func NewSceneManager ¶
func NewSceneManager() *SceneManager
func (*SceneManager) ActivationScheduled ¶
func (sm *SceneManager) ActivationScheduled() bool
func (*SceneManager) ActiveSceneName ¶
func (sm *SceneManager) ActiveSceneName() string
func (*SceneManager) Add ¶
func (sm *SceneManager) Add(scene Scene)
func (*SceneManager) Destroy ¶
func (sm *SceneManager) Destroy() error
func (*SceneManager) Get ¶
func (sm *SceneManager) Get(name string) Scene
func (*SceneManager) Has ¶
func (sm *SceneManager) Has(name string) bool
func (*SceneManager) Remove ¶
func (sm *SceneManager) Remove(name string, destroy bool) (bool, error)
func (*SceneManager) ScheduleActivation ¶
func (sm *SceneManager) ScheduleActivation(name string) error
func (*SceneManager) UpdateActiveScene ¶
func (sm *SceneManager) UpdateActiveScene(scenePtr *Scene) bool
type SplashScreen ¶
type SplashScreen struct {
// contains filtered or unexported fields
}
func MustNewSplashScreen ¶
func MustNewSplashScreen(w, h int32) *SplashScreen
func NewSplashScreen ¶
func NewSplashScreen(w, h int32) (*SplashScreen, error)
func (*SplashScreen) Destroy ¶
func (s *SplashScreen) Destroy() error
func (*SplashScreen) DisplayImage ¶
func (s *SplashScreen) DisplayImage(data []byte) error
func (*SplashScreen) Window ¶
func (s *SplashScreen) Window() *sdl.Window
Window returns the sdl.Window where the SplashScreen is shown in.
type Stage ¶
func MustNewStage ¶
MustNewStage creates a new Stage using NewStage and returns it on success. Any returned errors from NewStage are passed to FailOnErr and result in a fatal exit of the program.
func NewStage ¶
NewStage creates a new Stage by first creating a new sdl.Window and sdl.Renderer. These are configured with the provided Options.
func (*Stage) AddScene ¶
AddScene adds a new Scene to the SceneManager of the Stage. It also activates the Scene when no other Scene is currently active.
func (*Stage) ClearScreen ¶
func (*Stage) HandleKeyUpEvent ¶
func (s *Stage) HandleKeyUpEvent(e *sdl.KeyboardEvent) error
func (*Stage) HandleWindowSizeChangedEvent ¶
func (s *Stage) HandleWindowSizeChangedEvent(e *sdl.WindowEvent) error
func (*Stage) MustAddScene ¶
MustAddScene adds a Scene to the SceneManager, the same way AddScene does. Any errors are passed to FailOnErr.
func (*Stage) PresentScreen ¶
func (s *Stage) PresentScreen()
func (*Stage) SceneManager ¶
func (s *Stage) SceneManager() *SceneManager
SceneManager returns the SceneManager instance that handles switching of scenes for the Stage.
func (*Stage) SetWindowIcon ¶
func (*Stage) ToggleFullscreen ¶
func (*Stage) ToggleWindowTitleFps ¶
func (s *Stage) ToggleWindowTitleFps()
type TextureAtlas ¶
type TextureAtlas struct {
// contains filtered or unexported fields
}
func NewTextureAtlas ¶
func NewUniformTextureAtlas ¶
func (*TextureAtlas) Destroy ¶
func (ta *TextureAtlas) Destroy() error
func (*TextureAtlas) GetFomIndex ¶
func (ta *TextureAtlas) GetFomIndex(i int) (TextureClip, error)
func (*TextureAtlas) GetFromName ¶
func (ta *TextureAtlas) GetFromName(name string) (TextureClip, error)
func (*TextureAtlas) HasIndex ¶
func (ta *TextureAtlas) HasIndex(i int) bool
func (*TextureAtlas) HasName ¶
func (ta *TextureAtlas) HasName(name string) bool
func (*TextureAtlas) IsUniform ¶
func (ta *TextureAtlas) IsUniform() bool
func (*TextureAtlas) Len ¶
func (ta *TextureAtlas) Len() int
func (*TextureAtlas) Names ¶
func (ta *TextureAtlas) Names() []string
func (*TextureAtlas) Texture ¶
func (ta *TextureAtlas) Texture() *sdl.Texture
type TextureClip ¶
func (TextureClip) Size ¶
func (tc TextureClip) Size() (float64, float64)
type TexturesMap ¶
func (TexturesMap) Destroy ¶
func (t TexturesMap) Destroy(name string) error
func (TexturesMap) DestroyAll ¶
func (t TexturesMap) DestroyAll() error
Destroy destroys all sdl.Textures within the TexturesMap.
type Time ¶
type Time struct { LimitFps bool // contains filtered or unexported fields }
func (*Time) ConvTicks ¶
ConvTicks coverts a ticks value from sdl.GetTicks to a time.Time value. The result may be a few microseconds off but is well below a millisecond.
func (*Time) RegisterClock ¶
func (*Time) SetTargetFps ¶
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
debug
|
|
Package event defines interfaces for sdl.Event handling.
|
Package event defines interfaces for sdl.Event handling. |
Package geom defines a two-dimensional coordinate system.
|
Package geom defines a two-dimensional coordinate system. |
xform
Package xform supplies additional transform related features.
|
Package xform supplies additional transform related features. |
Package math provides additional game math related functions.
|
Package math provides additional game math related functions. |