sdl2

package
Version: v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Camera

type Camera struct{}

Camera wraps methods used to alter the offsets of the current rendering context.

func (*Camera) ScaleX

func (c *Camera) ScaleX() float32

ScaleX returns the current X-axis scale factor of the camera.

func (*Camera) ScaleY

func (c *Camera) ScaleY() float32

ScaleY returns the current Y-axis scale factor of the camera.

func (*Camera) SetPosition

func (c *Camera) SetPosition(x, y int32)

SetPosition sets the position of the camera relative to the world.

func (*Camera) SetScale

func (c *Camera) SetScale(x, y float32)

SetScale sets the scale factor of all rendering textures. This is multiplicative of the actual texture scale size.

func (*Camera) X

func (c *Camera) X() int32

X returns the current X offset in pixels relative to the world.

func (*Camera) Y

func (c *Camera) Y() int32

Y returns the current Y offset in pixels relative to the world.

type Font

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

Font wraps an SDL TTF Font and allows drawing to screen.

func (*Font) Close

func (f *Font) Close() error

Close releases the SDL font resource.

func (*Font) SetFont

func (f *Font) SetFont(fontPath string, size int) error

SetFont loads a new font. All future calls to Texture will use the newly loaded font.

func (*Font) Texture

func (f *Font) Texture(text string, color graphics.Color) (graphics.Texture, error)

Texture loads the font as a drawable texture. Texture must be closed manually.

type Keyboard

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

Keyboard wraps a map of SDL keys and their current states.

func (*Keyboard) IsKeyDown

func (k *Keyboard) IsKeyDown(keyCode input.Key) bool

IsKeyDown returns true if the given key is pressed.

func (*Keyboard) IsKeyPress

func (k *Keyboard) IsKeyPress(keyCode input.Key) bool

IsKeyPress returns true if the given key is pressed for the first time.

func (*Keyboard) IsKeyRelease

func (k *Keyboard) IsKeyRelease(keyCode input.Key) bool

IsKeyRelease returns true if the given key is release for the first time.

func (*Keyboard) IsKeyUp

func (k *Keyboard) IsKeyUp(keyCode input.Key) bool

IsKeyUp returns true of the given key is not pressed.

func (*Keyboard) UpdateKey

func (k *Keyboard) UpdateKey(keyCode input.Key, pressed, repeat bool)

UpdateKey updates the state of the given key to the keyboard state map.

type Mouse

type Mouse struct {
	X int32
	Y int32
	// contains filtered or unexported fields
}

Mouse wraps a map of SDL Mouse Buttons and their current states as well as the current mouse position.

func (*Mouse) IsButtonDown

func (m *Mouse) IsButtonDown(button input.MouseButton) bool

IsButtonDown returns true if the given mouse button is pressed.

func (*Mouse) IsButtonPress

func (m *Mouse) IsButtonPress(button input.MouseButton) bool

IsButtonPress returns true if the given mouse button is pressed for the first time.

func (*Mouse) IsButtonRelease

func (m *Mouse) IsButtonRelease(button input.MouseButton) bool

IsButtonRelease returns true if the given mouse button is released for the first time.

func (*Mouse) IsButtonUp

func (m *Mouse) IsButtonUp(button input.MouseButton) bool

IsButtonUp returns true if the given mouse button is not pressed.

func (*Mouse) IsClick

func (m *Mouse) IsClick(button input.MouseButton) (bool, int32, int32)

IsClick returns true if the given mouse button is pressed for the first time as well as its clicked coordinates

func (*Mouse) IsRelease

func (m *Mouse) IsRelease(button input.MouseButton) (bool, int32, int32)

IsRelease returns true if the given mouse button is released for the first time as well as its released coordinates

func (*Mouse) Pos

func (m *Mouse) Pos() (int32, int32)

Pos returns the current X and Y position of the mouse.

func (*Mouse) UpdateButton

func (m *Mouse) UpdateButton(button input.MouseButton, x, y int32, pressed bool)

UpdateButton updates the state of the given button to the mouse button state map.

func (*Mouse) UpdatePosition

func (m *Mouse) UpdatePosition(x, y int32)

UpdatePosition updates the mouse cursor position.

type Player

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

Player wraps needed methods for the audio.Player interface.

func (*Player) Close

func (p *Player) Close() error

Close releases audio player resources and stops all playback.

func (*Player) NewSound

func (p *Player) NewSound(soundPath string) (audio.Sound, error)

NewSound loads a WAV file into memory and converts it into a chunk. Sound must be closed manually.

func (*Player) SetVolume

func (p *Player) SetVolume(volume float32) error

SetVolume sets the volume across the entire SDL player. This will not hold true if new mixing channels are allocated beyond the default.

type SDL2

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

SDL2 implements the Driver interface.

func (*SDL2) Close

func (s *SDL2) Close()

Close safely releases SDL resources.

func (*SDL2) CreateWindow

func (s *SDL2) CreateWindow(x, y int32, title string) error

CreateWindow starts a new window and renderer which is ready to draw to.

func (*SDL2) DisableCursor

func (s *SDL2) DisableCursor() error

DisableCursor disables rendering of the hardware cursor.

func (*SDL2) EnableCursor

func (s *SDL2) EnableCursor() error

EnableCursor enables rendering of the hardware cursor.

func (*SDL2) Init

func (s *SDL2) Init() error

Init initializes everything in the SDL2 library.

func (*SDL2) NewAudioPlayer

func (s *SDL2) NewAudioPlayer() (audio.Player, error)

NewAudioPlayer initializes the SDL mixer and returns a default Player. Player must be closed manually.

func (*SDL2) NewCamera

func (s *SDL2) NewCamera() (graphics.Camera, error)

NewCamera sets the default offsets based on the current screen size.

func (*SDL2) NewFont

func (s *SDL2) NewFont(fontPath string, size int) (graphics.Font, error)

NewFont opens a TTF font and sets it up for use in rendering.

func (*SDL2) NewKeyboard

func (s *SDL2) NewKeyboard() input.Keyboard

NewKeyboard sets up an empty map of key states.

func (*SDL2) NewMouse

func (s *SDL2) NewMouse() input.Mouse

NewMouse sets up an empty map of mouse button states.

func (*SDL2) NewTexture

func (s *SDL2) NewTexture(imgPath string) (graphics.Texture, error)

NewTexture loads an image as an SDL texture. Texture must be closed manually.

func (*SDL2) NewTextureAtlas

func (s *SDL2) NewTextureAtlas(imgPath string, splitX, splitY int32) (graphics.TextureAtlas, error)

NewTextureAtlas loads an image as an SDL texture and splices it into separate rectangles for use in drawing.

func (*SDL2) PostDraw

func (s *SDL2) PostDraw()

PostDraw writes all new bytes to the renderer.

func (*SDL2) PreDraw

func (s *SDL2) PreDraw() error

PreDraw flushes the renderer and sets up for drawing.

func (*SDL2) SetBackgroundColor

func (s *SDL2) SetBackgroundColor(color *graphics.Color)

SetBackgroundColor sets the RGB value of the screen clear before each frame.

func (*SDL2) Update

func (s *SDL2) Update() error

Update parses through all new events SDL reports on and updates the state accordingly.

type Sound

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

Sound holds SDL chunk data for playback in use with the audio.Sound interface.

func (*Sound) Close

func (s *Sound) Close() error

Close frees the sdl chunk resource.

func (*Sound) Play

func (s *Sound) Play() error

Play begins playback of the Sound through the sdl mixer.

type Texture

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

Texture wraps an SDL Texture and allows writing to screen.

func (*Texture) Close

func (t *Texture) Close() error

Close releases the texture and the image from memory.

func (*Texture) Draw

func (t *Texture) Draw(x, y int32, scaleX, scaleY float32, rotation float64) error

Draw renders the texture to the SDL renderer.

func (*Texture) H

func (t *Texture) H() int32

H returns the height of the texture.

func (*Texture) W

func (t *Texture) W() int32

W returns the width of the texture.

type TextureAtlas

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

TextureAtlas wraps an SDL Texture. It splits the texture into tiles to allow for easy drawing of sprites in a spritesheet.

func (*TextureAtlas) Close

func (t *TextureAtlas) Close() error

Close releases the texture and the image from memory.

func (*TextureAtlas) Draw

func (t *TextureAtlas) Draw(tile int, x, y int32, scaleX, scaleY float32, rotation float64) error

Draw renders the texture of the given tile to the SDL renderer.

func (*TextureAtlas) Len

func (t *TextureAtlas) Len() int

Len returns the number of spliced tiles in the texture atlas.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto