Documentation ¶
Index ¶
- Constants
- Variables
- 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 Render(ren *sdl.Renderer, renderables ...Renderable) error
- func RunLoop(stage *Stage) error
- func ShrinkRect(rect sdl.Rect, amount int32) sdl.Rect
- 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) TextureClip(file string) (tc TextureClip, err error)
- func (l *AssetsLoader) UniformTextureAtlas(file string, w, h int32, total uint8) (*TextureAtlas, error)
- type Camera
- func (c *Camera) Disable()
- func (c *Camera) Enable()
- func (c *Camera) Follow(target geom.XYGetter)
- func (c *Camera) GetX() float64
- func (c *Camera) GetY() float64
- func (c *Camera) Height() int32
- func (c *Camera) IsEnabled() bool
- func (c *Camera) Resize(w, h int32)
- func (c *Camera) SetX(x float64)
- func (c *Camera) SetY(y float64)
- func (c *Camera) TranslateX(x int32) int32
- func (c *Camera) TranslateXF(x float64) int32
- func (c *Camera) TranslateY(y int32) int32
- func (c *Camera) TranslateYF(y float64) int32
- func (c *Camera) Width() int32
- type Canvas
- func (c *Canvas) BeginFill(color sdl.Color)
- func (c *Canvas) BeginFillAlpha(color sdl.Color, alpha uint8)
- func (c *Canvas) BeginFillRGBA(r, g, b, a uint8)
- func (c *Canvas) BeginLineStyle(thickness int32, color sdl.Color)
- func (c *Canvas) Camera() *Camera
- func (c *Canvas) CreateTexture(format uint32, access int, w, h int32) (*sdl.Texture, error)
- func (c *Canvas) CreateTextureClip(format uint32, access int, w, h int32) (TextureClip, error)
- func (c *Canvas) Done() (err error)
- func (c *Canvas) Draw(d Drawable)
- func (c *Canvas) DrawCircle(x, y, rad int32)
- func (c *Canvas) DrawCircleF(x, y, rad float64)
- func (c *Canvas) DrawEllipse(x, y, radX, radY int32)
- func (c *Canvas) DrawEllipseF(x, y, rx, ry float64)
- func (c *Canvas) DrawLine(x1, y1, x2, y2 int32)
- func (c *Canvas) DrawLineF(x1, y1, x2, y2 float64)
- func (c *Canvas) DrawPixel(x, y, size int32)
- func (c *Canvas) DrawPixelF(x, y float64, size int32)
- func (c *Canvas) DrawPolygon(vx, vy []int16)
- func (c *Canvas) DrawRect(x, y, w, h int32)
- func (c *Canvas) DrawRectF(x, y, w, h float64)
- func (c *Canvas) DrawRoundRect(x, y, w, h, rad int32)
- func (c *Canvas) DrawRoundRectF(x, y, w, h, rad float64)
- func (c *Canvas) DrawSdlFPoint(pt sdl.FPoint, size int32)
- func (c *Canvas) DrawSdlFRect(rect sdl.FRect)
- func (c *Canvas) DrawSdlPoint(pt sdl.Point, size int32)
- func (c *Canvas) DrawSdlRect(rect sdl.Rect)
- func (c *Canvas) DrawTexture(tx *sdl.Texture, src *sdl.Rect, dest sdl.Rect)
- func (c *Canvas) DrawTextureClip(clip TextureClip, dest sdl.Rect)
- func (c *Canvas) DrawTextureClipEx(clip TextureClip, dest sdl.Rect, deg float64, origin sdl.Point, ...)
- func (c *Canvas) DrawTextureEx(tx *sdl.Texture, src *sdl.Rect, dest sdl.Rect, deg float64, origin sdl.Point, ...)
- func (c *Canvas) EndFill()
- func (c *Canvas) EndLineStyle()
- func (c *Canvas) GetFill() (sdl.Color, bool)
- func (c *Canvas) GetLineStyle() (int32, sdl.Color, bool)
- func (c *Canvas) Render(r Renderable)
- func (c *Canvas) Renderer() *sdl.Renderer
- func (c *Canvas) SetCamera(cam *Camera)
- func (c *Canvas) SetDrawAntiAlias(aa bool)
- func (c *Canvas) SetDrawBlendMode(mode sdl.BlendMode)
- type Clock
- type Drawable
- type DrawableFunc
- type FontsMap
- type Layer
- type Options
- type Renderable
- type RenderableFunc
- 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) Canvas() *Canvas
- func (s *Stage) Center() (float64, float64)
- func (s *Stage) ClearScreen() error
- 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) TextureClip ¶
func (l *AssetsLoader) TextureClip(file string) (tc TextureClip, err error)
func (*AssetsLoader) UniformTextureAtlas ¶
func (l *AssetsLoader) UniformTextureAtlas(file string, w, h int32, total uint8) (*TextureAtlas, error)
type Camera ¶
type Camera struct {
// contains filtered or unexported fields
}
Convert world positions to screen positions https://gamedev.stackexchange.com/questions/121421/how-to-use-the-sdl-viewport-properly https://www.youtube.com/watch?v=D1dw7L0nC6s
func (*Camera) TranslateX ¶
func (*Camera) TranslateXF ¶
func (*Camera) TranslateY ¶
func (*Camera) TranslateYF ¶
type Canvas ¶
type Canvas struct {
// contains filtered or unexported fields
}
func (*Canvas) BeginFillRGBA ¶
func (*Canvas) CreateTexture ¶
func (*Canvas) CreateTextureClip ¶
func (*Canvas) DrawCircle ¶
func (*Canvas) DrawCircleF ¶
func (*Canvas) DrawEllipse ¶
func (*Canvas) DrawEllipseF ¶
func (*Canvas) DrawPixelF ¶
func (*Canvas) DrawPolygon ¶
func (*Canvas) DrawRoundRect ¶
func (*Canvas) DrawRoundRectF ¶
func (*Canvas) DrawSdlFRect ¶
func (*Canvas) DrawSdlRect ¶
func (*Canvas) DrawTexture ¶
func (*Canvas) DrawTextureClip ¶
func (c *Canvas) DrawTextureClip(clip TextureClip, dest sdl.Rect)
func (*Canvas) DrawTextureClipEx ¶
func (c *Canvas) DrawTextureClipEx(clip TextureClip, dest sdl.Rect, deg float64, origin sdl.Point, flip sdl.RendererFlip)
func (*Canvas) DrawTextureEx ¶
func (*Canvas) EndLineStyle ¶
func (c *Canvas) EndLineStyle()
func (*Canvas) Render ¶
func (c *Canvas) Render(r Renderable)
func (*Canvas) SetDrawAntiAlias ¶
func (*Canvas) SetDrawBlendMode ¶
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 DrawableFunc func(canvas *Canvas)
func (DrawableFunc) Draw ¶
func (fn DrawableFunc) Draw(canvas *Canvas)
type Layer ¶
type Layer []Renderable
func (*Layer) Append ¶
func (l *Layer) Append(d ...Renderable)
func (*Layer) Prepend ¶
func (l *Layer) Prepend(d ...Renderable)
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 Renderable ¶
type RenderableFunc ¶
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. |