Documentation ¶
Overview ¶
nimble is a Go package for simple 2D video games.
It's a Go incarnation of a lightweight graphics interface that I use for video games. The games typically involve unusual rendering not handled by hardware accelerators. Hence the interface focuses on providing simple efficient access to bitmaps in memory.
The other purpose of the package is be a thin wrapper that can be wrapped around a variety of host platforms. The initial port is against go-sdl2 (https://github.com/veandco/go-sdl2).
When used for production, it should be built with `-tags=release`.
Index ¶
- Constants
- func AddKeyObserver(k KeyObserver)
- func AddMouseObserver(m MouseObserver)
- func AddRenderClient(r renderClient)
- func CreateRecordFile(filename string) (file *os.File, err error)
- func MouseState() (x, y int32, isDown bool)
- func Now() float64
- func OpenRecordFile(filename string) (*os.File, error)
- func PlaySound(waveform []float32, relativeAmplitude, relativePitch float32)
- func Quit()
- func Run(win WindowSpec) int
- func ShowCursor(show bool)
- type Font
- type Key
- type KeyObserver
- type MouseEvent
- type MouseObserver
- type PixMap
- func (pm *PixMap) Contains(x, y int32) bool
- func (dst *PixMap) Copy(x0, y0 int32, src *PixMap)
- func (pm *PixMap) DrawRect(r Rect, color Pixel)
- func (pm *PixMap) DrawText(x, y int32, text string, color Pixel, font *Font) (width, height int32)
- func (pm *PixMap) Empty() bool
- func (pm *PixMap) Fill(color Pixel)
- func (pm *PixMap) Height() int32
- func (pm *PixMap) Intersect(r Rect) (result PixMap)
- func (pm *PixMap) Pixel(x int32, y int32) Pixel
- func (pm *PixMap) Row(y int32) []Pixel
- func (pm *PixMap) SetPixel(x, y int32, color Pixel)
- func (pm *PixMap) Size() (w, h int32)
- func (pm *PixMap) Width() int32
- type Pixel
- type Rect
- type WindowSpec
Constants ¶
const ( Black = Pixel(0xFF000000) White = Pixel(0xFFFFFFFF) )
Predefined pixel constants.
const ( KeyBackspace = Key(8) KeyTab = Key(9) KeyReturn = Key(0xD) KeyEscape = Key(0x1B) KeyDelete = Key(0x7F) KeyLeft = Key(0x11 + iota) // Borrow "device control" codes KeyRight KeyUp KeyDown )
Key values for non-printing keys.
const ( MouseMove = MouseEvent(iota) // Mouse moved with button up MouseDown // Button pressed MouseUp // Button released MouseDrag // Mouse moved with button down )
Kinds of mouse events.
const SampleRate = 44100.0
Nominal sample rate for waveforms.
Variables ¶
This section is empty.
Functions ¶
func AddKeyObserver ¶
func AddKeyObserver(k KeyObserver)
AddKeyObserver causes KeyObserver k to be notified of key events.
func AddMouseObserver ¶
func AddMouseObserver(m MouseObserver)
AddMouseObserver causes m to be notified of mouse events.
func AddRenderClient ¶
func AddRenderClient(r renderClient)
Types ¶
type Font ¶
A Font
type Key ¶
type Key uint8
A Key represents a key on the keyoard. Printable ASCII values represent themselves.
type KeyObserver ¶
type KeyObserver interface {
KeyDown(Key)
}
A KeyObserver is notified of key events.
type MouseEvent ¶
type MouseEvent uint8
type MouseObserver ¶
type MouseObserver interface {
ObserveMouse(event MouseEvent, x, y int32)
}
A MouseObserver observes mousse events.
type PixMap ¶
type PixMap struct {
// contains filtered or unexported fields
}
A PixMap is a reference to a 2D array or subarray of pixels.
func MakePixMap ¶
MakePixMap makes a PixMap referring to pixels in the given slice. The following identities describe the mapping:
pixels[0] maps to (0,0). pixels[1] maps to (1,0). pixels[vstride] to (0,1).
func ReadPixMap ¶
ReadPixMap reads a PixMap from a file with the given name.
func (*PixMap) DrawText ¶
DrawText draws the given text at (x,y) on pm, in the given color and font. The return value indicates the width and height of a bounding box for the text.
func (*PixMap) Intersect ¶
Intersect returns a PixMap referencing the pixels in the intersection of a PixMap and a Rect.
func (*PixMap) Row ¶
Row returns a slice referring to the pixels with the given y coordinate. For example:
pm.Row(y)[x]
refers to the same pixel as:
pm.Pixel(x,y)
type Pixel ¶
type Pixel uint32
A pixel value. Currently the format is ARGB, but this might change in the future. Use the Pixel constructing functions RGB and Gray to construct pixels.
func Gray ¶
Gray constructs a Pixel with equal red, green, and blue components. frac should be in the interval [0,1]
func PixelSliceFromByteSlice ¶
Creates a slice of Pixel from a raw pointer
type Rect ¶
type Rect struct {
Left, Top, Right, Bottom int32
}
A rectangle or bounding box. The bounds form the product of half-open intervals [Left,Right) x [Top,Bottom)