Documentation ¶
Overview ¶
Package ebiten provides graphics and input API to develop a 2D game.
You can start the game by calling the function Run.
func update(screen *ebiten.Screen) { // Define your game. } func main() { ebiten.Run(update, 320, 240, 2, "Your game's title") }
Index ¶
- Constants
- func CursorPosition() (x, y int)
- func IsKeyPressed(key Key) bool
- func IsMouseButtonPressed(mouseButton MouseButton) bool
- func Run(f func(*Image) error, width, height, scale int, title string) error
- type ColorM
- type DrawImageOptions
- type Filter
- type GeoM
- type Image
- func (i *Image) At(x, y int) color.Color
- func (i *Image) Bounds() image.Rectangle
- func (i *Image) Clear() (err error)
- func (i *Image) ColorModel() color.Model
- func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error)
- func (i *Image) Fill(clr color.Color) (err error)
- func (i *Image) Size() (width, height int)
- type ImagePart
- type Key
- type MouseButton
Constants ¶
const ( FilterNearest = Filter(opengl.FilterNearest) FilterLinear = Filter(opengl.FilterLinear) )
Filters
const ColorMDim = 5
ColorMDim is a dimension of a ColorM.
const GeoMDim = 3
GeoMDim is a dimension of a GeoM.
Variables ¶
This section is empty.
Functions ¶
func CursorPosition ¶
func CursorPosition() (x, y int)
CursorPosition returns a position of a mouse cursor.
func IsKeyPressed ¶
IsKeyPressed returns a boolean indicating whether key is pressed.
func IsMouseButtonPressed ¶
func IsMouseButtonPressed(mouseButton MouseButton) bool
IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
func Run ¶
Run runs the game. f is a function which is called at every frame. The argument (*Image) is the render target that represents the screen.
This function must be called from the main thread.
The given function f is expected to be called 60 times a second, but this is not strictly guaranteed. If you need to care about time, you need to check current time every time f is called.
Types ¶
type ColorM ¶
type ColorM struct {
// contains filtered or unexported fields
}
A ColorM represents a matrix to transform coloring when rendering an image.
A ColorM is applied to the source alpha color while an Image's pixels' format is alpha premultiplied. Before applying a matrix, a color is un-multiplied, and after applying the matrix, the color is multiplied again.
The initial value is identity.
func Monochrome ¶
func Monochrome() ColorM
Monochrome returns a color matrix to make an image monochrome.
func ScaleColor ¶
ScaleColor returns a color matrix that scales a color matrix by the given color (r, g, b, a).
func TranslateColor ¶
TranslateColor returns a color matrix that translates a color matrix by the given color (r, g, b, a).
func (*ColorM) SetElement ¶
SetElement sets an element at (i, j).
type DrawImageOptions ¶
A DrawImageOptions represents options to render an image on an image.
type Filter ¶
Filter represents the type of filter to be used when an image is maginified or minified.
type GeoM ¶
type GeoM struct {
// contains filtered or unexported fields
}
A GeoM represents a matrix to transform geometry when rendering an image.
The initial value is identity.
func TranslateGeo ¶
TranslateGeo returns a matrix taht translates a geometry matrix by (tx, ty).
func (*GeoM) SetElement ¶
SetElement sets an element at (i, j).
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents an image. The pixel format is alpha-premultiplied. Image implements image.Image.
func NewImageFromImage ¶
NewImageFromImage creates a new image with the given image (img).
func (*Image) At ¶
At returns the color of the image at (x, y).
This method loads pixels from GPU to VRAM if necessary.
func (*Image) ColorModel ¶
ColorModel returns the color model of the image.
func (*Image) DrawImage ¶
func (i *Image) DrawImage(image *Image, options *DrawImageOptions) (err error)
DrawImage draws the given image on the receiver image.
This method accepts the options. The parts of the given image at the parts of the destination. After determining parts to draw, this applies the geometry matrix and the color matrix.
Here are the default values:
Parts: (0, 0) - (source width, source height) to (0, 0) - (source width, source height) (i.e. the whole source image) GeoM: Identity matrix ColorM: Identity matrix (that changes no colors)
type MouseButton ¶
type MouseButton int
A MouseButton represents a mouse button.
const ( MouseButtonLeft MouseButton = iota MouseButtonRight MouseButtonMiddle MouseButtonMax )
MouseButtons