Documentation ¶
Overview ¶
Package ebiten provides graphics and input API to develop a 2D game.
You can start the game by calling the function Run.
// update is called every frame (1/60 [s]). func update(screen *ebiten.Image) error { // Write your game's logical update. if IsDrawingSkipped() { // When the game is running slowly, the rendering result // will not be adopted. return nil } // Write your game's rendering. return nil } func main() { // Call ebiten.Run to start your game loop. ebiten.Run(update, 320, 240, 2, "Your game's title") }
The EBITEN_SCREENSHOT_KEY environment variable specifies the key to take a screenshot. For example, if you run your game with `EBITEN_SCREENSHOT_KEY=q`, you can take a game screen's screenshot by pressing Q key.
The EBITEN_INTERNAL_IMAGES_KEY environment variable specifies the key to dump all the internal images. This is valid only when the build tag 'ebitendebug' is specified.
In the API document, 'the main thread' means the goroutine in init(), main() and their callees without 'go' statement. It is assured that 'the main thread' runs on the OS main thread. There are some Ebiten functions that must be called on the main thread under some conditions (typically, before ebiten.Run is called).
Index ¶
- Constants
- Variables
- func CurrentFPS() float64
- func CurrentTPS() float64
- func CursorPosition() (x, y int)
- func DeviceScaleFactor() float64
- func GamepadAxis(id int, axis int) float64
- func GamepadAxisNum(id int) int
- func GamepadButtonNum(id int) int
- func GamepadIDs() []int
- func InputChars() []rune
- func IsCursorVisible() bool
- func IsDrawingSkipped() bool
- func IsFullscreen() bool
- func IsGamepadButtonPressed(id int, button GamepadButton) bool
- func IsKeyPressed(key Key) bool
- func IsMouseButtonPressed(mouseButton MouseButton) bool
- func IsRunnableInBackground() bool
- func IsRunningSlowly() bool
- func IsVsyncEnabled() bool
- func IsWindowDecorated() bool
- func MaxTPS() int
- func MonitorSize() (int, int)
- func Run(f func(*Image) error, width, height int, scale float64, title string) error
- func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64, title string) <-chan error
- func ScreenScale() float64
- func ScreenSizeInFullscreen() (int, int)
- func SetCursorVisibility(visible bool)
- func SetCursorVisible(visible bool)
- func SetFullscreen(fullscreen bool)
- func SetMaxTPS(tps int)
- func SetRunnableInBackground(runnableInBackground bool)
- func SetScreenScale(scale float64)
- func SetScreenSize(width, height int)
- func SetVsyncEnabled(enabled bool)
- func SetWindowDecorated(decorated bool)
- func SetWindowIcon(iconImages []image.Image)
- func SetWindowTitle(title string)
- func TouchIDs() []int
- func TouchPosition(id int) (int, int)
- func Wheel() (xoff, yoff float64)
- type ColorM
- func (c *ColorM) Add(other ColorM)
- func (c *ColorM) Apply(clr color.Color) color.Color
- func (c *ColorM) ChangeHSV(hueTheta float64, saturationScale float64, valueScale float64)
- func (c *ColorM) Concat(other ColorM)
- func (c *ColorM) Element(i, j int) float64
- func (c *ColorM) Reset()
- func (c *ColorM) RotateHue(theta float64)
- func (c *ColorM) Scale(r, g, b, a float64)
- func (c *ColorM) SetElement(i, j int, element float64)
- func (c *ColorM) String() string
- func (c *ColorM) Translate(r, g, b, a float64)
- type CompositeMode
- type DrawImageOptions
- type DrawTrianglesOptions
- type Filter
- type GamepadButton
- type GeoM
- func (g *GeoM) Add(other GeoM)
- func (g *GeoM) Apply(x, y float64) (float64, float64)
- func (g *GeoM) Concat(other GeoM)
- func (g *GeoM) Element(i, j int) float64
- func (g *GeoM) Invert()
- func (g *GeoM) IsInvertible() bool
- func (g *GeoM) Reset()
- func (g *GeoM) Rotate(theta float64)
- func (g *GeoM) Scale(x, y float64)
- func (g *GeoM) SetElement(i, j int, element float64)
- func (g *GeoM) Skew(skewX, skewY float64)
- func (g *GeoM) String() string
- func (g *GeoM) Translate(tx, ty float64)
- type Image
- func (i *Image) At(x, y int) color.Color
- func (i *Image) Bounds() image.Rectangle
- func (i *Image) Clear() error
- func (i *Image) ColorModel() color.Model
- func (i *Image) Dispose() error
- func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error
- func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions)
- func (i *Image) Fill(clr color.Color) error
- func (i *Image) ReplacePixels(p []byte) error
- func (i *Image) Size() (width, height int)
- type ImagePart
- type ImageParts
- type Key
- type MouseButton
- type Touch
- type Vertex
Constants ¶
const ColorMDim = affine.ColorMDim
ColorMDim is a dimension of a ColorM.
const DefaultTPS = 60
TPS represents a default ticks per second, that represents how many times game updating happens in a second.
const FPS = DefaultTPS
FPS is deprecated as of 1.8.0-alpha: Use DefaultTPS instead.
const GeoMDim = 3
GeoMDim is a dimension of a GeoM.
const UncappedTPS = clock.UncappedTPS
UncappedTPS is a special TPS value that means the game doesn't have limitation on TPS.
Variables ¶
var MaxImageSize = 4096
MaxImageSize is deprecated as of 1.7.0-alpha. No replacement so far.
TODO: Make this replacement (#541)
Functions ¶
func CurrentFPS ¶ added in v1.2.0
func CurrentFPS() float64
CurrentFPS returns the current number of FPS (frames per second), that represents how many swapping buffer happens per second.
On some environments, CurrentFPS doesn't return a reliable value since vsync doesn't work well there. If you want to measure the application's speed, Use CurrentTPS.
CurrentFPS is concurrent-safe.
func CurrentTPS ¶ added in v1.8.0
func CurrentTPS() float64
CurrentTPS returns the current TPS (ticks per second), that represents how many update function is called in a second.
CurrentTPS is concurrent-safe.
func CursorPosition ¶
func CursorPosition() (x, y int)
CursorPosition returns a position of a mouse cursor.
CursorPosition is concurrent-safe.
func DeviceScaleFactor ¶ added in v1.6.0
func DeviceScaleFactor() float64
DeviceScaleFactor returns a device scale factor value of the current monitor which the window belongs to.
DeviceScaleFactor returns a meaningful value on high-DPI display environment, otherwise DeviceScaleFactor returns 1.
DeviceScaleFactor might panic on init function on some devices like Android. Then, it is not recommended to call DeviceScaleFactor from init functions.
DeviceScaleFactor must be called on the main thread before ebiten.Run, and is concurrent-safe after ebiten.Run.
func GamepadAxis ¶ added in v1.2.0
GamepadAxis returns the float value [-1.0 - 1.0] of the given gamepad (id)'s axis (axis).
GamepadAxis is concurrent-safe.
GamepadAxis always returns 0 on mobiles.
func GamepadAxisNum ¶ added in v1.2.0
GamepadAxisNum returns the number of axes of the gamepad (id).
GamepadAxisNum is concurrent-safe.
GamepadAxisNum always returns 0 on mobiles.
func GamepadButtonNum ¶ added in v1.2.0
GamepadButtonNum returns the number of the buttons of the given gamepad (id).
GamepadButtonNum is concurrent-safe.
GamepadButtonNum always returns 0 on mobiles.
func GamepadIDs ¶ added in v1.6.0
func GamepadIDs() []int
GamepadIDs returns a slice indicating available gamepad IDs.
GamepadIDs is concurrent-safe.
GamepadIDs always returns an empty slice on mobiles.
func InputChars ¶ added in v1.6.0
func InputChars() []rune
InputChars return "printable" runes read from the keyboard at the time update is called.
InputChars represents the environment's locale-dependent translation of keyboard input to Unicode characters.
IsKeyPressed is based on a mapping of device (US keyboard) codes to input device keys. "Control" and modifier keys should be handled with IsKeyPressed.
InputChars is concurrent-safe.
func IsCursorVisible ¶ added in v1.6.0
func IsCursorVisible() bool
IsCursorVisible returns a boolean value indicating whether the cursor is visible or not.
IsCursorVisible always returns false on mobiles.
IsCursorVisible is concurrent-safe.
func IsDrawingSkipped ¶ added in v1.8.0
func IsDrawingSkipped() bool
IsDrawingSkipped returns true if rendering result is not adopted. It is recommended to skip drawing images or screen when IsDrawingSkipped is true.
The typical code with IsDrawingSkipped is this:
func update(screen *ebiten.Image) error { // Update the state. // When IsDrawingSkipped is true, the rendered result is not adopted. // Skip rendering then. if ebiten.IsDrawingSkipped() { return nil } // Draw something to the screen. return nil }
IsDrawingSkipped is concurrent-safe.
func IsFullscreen ¶ added in v1.6.0
func IsFullscreen() bool
IsFullscreen returns a boolean value indicating whether the current mode is fullscreen or not.
IsFullscreen always returns false on mobiles.
IsFullscreen is concurrent-safe.
func IsGamepadButtonPressed ¶ added in v1.2.0
func IsGamepadButtonPressed(id int, button GamepadButton) bool
IsGamepadButtonPressed returns the boolean indicating the given button of the gamepad (id) is pressed or not.
IsGamepadButtonPressed is concurrent-safe.
The relationships between physical buttons and buttion IDs depend on environments. There can be differences even between Chrome and Firefox.
IsGamepadButtonPressed always returns false on mobiles.
func IsKeyPressed ¶
IsKeyPressed returns a boolean indicating whether key is pressed.
Known issue: On Edge browser, some keys don't work well:
- KeyKPEnter and KeyKPEqual are recognized as KeyEnter and KeyEqual.
- KeyPrintScreen is only treated at keyup event.
IsKeyPressed is concurrent-safe.
func IsMouseButtonPressed ¶
func IsMouseButtonPressed(mouseButton MouseButton) bool
IsMouseButtonPressed returns a boolean indicating whether mouseButton is pressed.
IsMouseButtonPressed is concurrent-safe.
Note that touch events not longer affect IsMouseButtonPressed's result as of 1.4.0-alpha. Use Touches instead.
func IsRunnableInBackground ¶ added in v1.6.0
func IsRunnableInBackground() bool
IsRunnableInBackground returns a boolean value indicating whether the game runs even in background.
IsRunnableInBackground is concurrent-safe.
func IsRunningSlowly ¶ added in v1.3.0
func IsRunningSlowly() bool
IsRunningSlowly is deprecated as of 1.8.0-alpha. Use IsDrawingSkipped instead.
func IsVsyncEnabled ¶ added in v1.8.0
func IsVsyncEnabled() bool
IsVsyncEnabled returns a boolean value indicating whether the game uses the display's vsync.
IsVsyncEnabled is concurrent-safe.
func IsWindowDecorated ¶ added in v1.7.0
func IsWindowDecorated() bool
IsWindowDecorated returns a boolean value indicating whether the window is decorated.
IsWindowDecorated is concurrent-safe.
func MaxTPS ¶ added in v1.8.0
func MaxTPS() int
MaxTPS returns the current maximum TPS.
MaxTPS is concurrent-safe.
func MonitorSize ¶ added in v1.7.0
MonitorSize is deprecated as of 1.8.0-alpha. Use ScreenSizeInFullscreen instead.
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. The screen size is based on the given values (width and height).
A window size is based on the given values (width, height and scale). scale is used to enlarge the screen. Note that the actual screen is multiplied not only by the given scale but also by the device scale on high-DPI display. If you pass inverse of the device scale, you can disable this automatical device scaling as a result. You can get the device scale by DeviceScaleFactor function.
Run must be called on the main thread. Note that Ebiten bounds the main goroutine to the main OS thread by runtime.LockOSThread.
Ebiten tries to call f 60 times a second. In other words, TPS (ticks per second) is 60. This is not related to framerate (display's refresh rate).
f is not called when the window is in background by default. This setting is configurable with SetRunnableInBackground.
The given scale is ignored on fullscreen mode or gomobile-build mode.
Run returns error when 1) OpenGL error happens, 2) audio error happens or 3) f returns error. In the case of 3), Run returns the same error.
The size unit is device-independent pixel.
Don't call Run twice or more in one process.
func RunWithoutMainLoop ¶ added in v1.4.0
func RunWithoutMainLoop(f func(*Image) error, width, height int, scale float64, title string) <-chan error
RunWithoutMainLoop runs the game, but don't call the loop on the main (UI) thread. Different from Run, RunWithoutMainLoop returns immediately.
Ebiten users should NOT call RunWithoutMainLoop. Instead, functions in github.com/hajimehoshi/ebiten/mobile package calls this.
func ScreenScale ¶ added in v1.3.0
func ScreenScale() float64
ScreenScale returns the current screen scale.
If Run is not called, this returns 0.
ScreenScale is concurrent-safe.
func ScreenSizeInFullscreen ¶ added in v1.8.0
ScreenSizeInFullscreen returns the size in device-independent pixels when the game is fullscreen. The adopted monitor is the 'current' monitor which the window belongs to. The returned value can be given to Run or SetSize function if the perfectly fit fullscreen is needed.
On browsers, ScreenSizeInFullscreen returns the 'window' (global object) size, not 'screen' size since an Ebiten game should not know the outside of the window object. For more detials, see SetFullscreen API comment.
On mobiles, ScreenSizeInFullscreen returns (0, 0) so far.
If you use this for screen size with SetFullscreen(true), you can get the fullscreen mode which size is well adjusted with the monitor.
w, h := ScreenSizeInFullscreen() ebiten.SetFullscreen(true) ebiten.Run(update, w, h, 1, "title")
Furthermore, you can use them with DeviceScaleFactor(), you can get the finest fullscreen mode.
s := ebiten.DeviceScaleFactor() w, h := ScreenSizeInFullscreen() ebiten.SetFullscreen(true) ebiten.Run(update, int(float64(w) * s), int(float64(h) * s), 1/s, "title")
For actual example, see examples/fullscreen
ScreenSizeInFullscreen must be called on the main thread before ebiten.Run, and is concurrent-safe after ebiten.Run.
func SetCursorVisibility ¶ added in v1.5.0
func SetCursorVisibility(visible bool)
SetCursorVisibility is deprecated as of 1.6.0-alpha. Use SetCursorVisible instead.
func SetCursorVisible ¶ added in v1.6.0
func SetCursorVisible(visible bool)
SetCursorVisible changes the state of cursor visiblity.
SetCursorVisible does nothing on mobiles.
SetCursorVisible is concurrent-safe.
func SetFullscreen ¶ added in v1.6.0
func SetFullscreen(fullscreen bool)
SetFullscreen changes the current mode to fullscreen or not.
On fullscreen mode, the game screen is automatically enlarged to fit with the monitor. The current scale value is ignored.
On desktops, Ebiten uses 'windowed' fullscreen mode, which doesn't change your monitor's resolution.
On browsers, the game screen is resized to fit with the body element (client) size. Additionally, the game screen is automatically resized when the body element is resized. Note that this has nothing to do with 'screen' which is outside of 'window'. It is recommended to put Ebiten game in an iframe, and if you want to make the game 'fullscreen' on browsers with Fullscreen API, you can do this by applying the API to the iframe.
SetFullscreen does nothing on mobiles.
SetFullscreen is concurrent-safe.
func SetMaxTPS ¶ added in v1.8.0
func SetMaxTPS(tps int)
SetMaxTPS sets the maximum TPS (ticks per second), that represents how many updating function is called per second. The initial value is 60.
If tps is UncappedTPS, TPS is uncapped and the game is updated per frame. If tps is negative but not UncappedTPS, SetMaxTPS panics.
SetMaxTPS is concurrent-safe.
func SetRunnableInBackground ¶ added in v1.6.0
func SetRunnableInBackground(runnableInBackground bool)
SetRunnableInBackground sets the state if the game runs even in background.
If the given value is true, the game runs in background e.g. when losing focus. The initial state is false.
Known issue: On browsers, even if the state is on, the game doesn't run in background tabs. This is because browsers throttles background tabs not to often update.
SetRunnableInBackground does nothing on mobiles so far.
SetRunnableInBackground is concurrent-safe.
func SetScreenScale ¶ added in v1.2.0
func SetScreenScale(scale float64)
SetScreenScale changes the scale of the screen.
Note that the actual screen is multiplied not only by the given scale but also by the device scale on high-DPI display. If you pass inverse of the device scale, you can disable this automatical device scaling as a result. You can get the device scale by DeviceScaleFactor function.
SetScreenScale is concurrent-safe.
func SetScreenSize ¶ added in v1.2.0
func SetScreenSize(width, height int)
SetScreenSize changes the (logical) size of the screen. This doesn't affect the current scale of the screen.
Unit is device-independent pixel.
SetScreenSize is concurrent-safe.
func SetVsyncEnabled ¶ added in v1.8.0
func SetVsyncEnabled(enabled bool)
SetVsyncEnabled sets a boolean value indicating whether the game uses the display's vsync.
If the given value is true, the game tries to sync the display's refresh rate. If false, the game ignores the display's refresh rate. The initial value is true. By disabling vsync, the game works more efficiently but consumes more CPU.
Note that the state doesn't affect TPS (ticks per second, i.e. how many the run funciton is updated per second).
SetVsyncEnabled does nothing on mobiles so far.
SetVsyncEnabled is concurrent-safe.
func SetWindowDecorated ¶ added in v1.7.0
func SetWindowDecorated(decorated bool)
SetWindowDecorated sets the state if the window is decorated.
SetWindowDecorated works only on desktops. SetWindowDecorated does nothing on other platforms.
SetWindowDecorated panics if SetWindowDecorated is called after Run.
SetWindowDecorated is concurrent-safe.
func SetWindowIcon ¶ added in v1.6.0
SetWindowIcon sets the icon of the game window.
If len(iconImages) is 0, SetWindowIcon reverts the icon to the default one.
For desktops, see the document of glfwSetWindowIcon of GLFW 3.2:
This function sets the icon of the specified window. If passed an array of candidate images, those of or closest to the sizes desired by the system are selected. If no images are specified, the window reverts to its default icon. The desired image sizes varies depending on platform and system settings. The selected images will be rescaled as needed. Good sizes include 16x16, 32x32 and 48x48.
As macOS windows don't have icons, SetWindowIcon doesn't work on macOS.
SetWindowIcon doesn't work on browsers or mobiles.
SetWindowIcon is concurrent-safe.
func SetWindowTitle ¶ added in v1.7.0
func SetWindowTitle(title string)
SetWindowTitle sets the title of the window.
SetWindowTitle does nothing on mobiles.
SetWindowTitle is concurrent-safe.
func TouchIDs ¶ added in v1.7.0
func TouchIDs() []int
TouchIDs returns the current touch states.
TouchIDs returns nil when there are no touches. TouchIDs always returns nil on desktops.
TouchIDs is concurrent-safe.
func TouchPosition ¶ added in v1.7.0
TouchPosition returns the position for the touch of the specified ID.
If the touch of the specified ID is not present, TouchPosition returns (0, 0).
TouchPosition is cuncurrent-safe.
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 straight 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 is deprecated as of 1.6.0-alpha. Use ChangeHSV(0, 0, 1) instead.
func ScaleColor ¶
ScaleColor is deprecated as of 1.2.0-alpha. Use Scale instead.
func TranslateColor ¶
TranslateColor is deprecated as of 1.2.0-alpha. Use Translate instead.
func (*ColorM) Add ¶
Add is deprecated as of 1.5.0-alpha. Note that this doesn't make sense as an operation for affine matrices.
func (*ColorM) Apply ¶ added in v1.6.0
Apply pre-multiplies a vector (r, g, b, a, 1) by the matrix where r, g, b, and a are clr's values in straight-alpha format. In other words, Apply calculates ColorM * (r, g, b, a, 1)^T.
func (*ColorM) ChangeHSV ¶ added in v1.3.0
ChangeHSV changes HSV (Hue-Saturation-Value) values. hueTheta is a radian value to rotate hue. saturationScale is a value to scale saturation. valueScale is a value to scale value (a.k.a. brightness).
This conversion uses RGB to/from YCrCb conversion.
func (*ColorM) Concat ¶
Concat multiplies a color matrix with the other color matrix. This is same as muptiplying the matrix other and the matrix c in this order.
func (*ColorM) Reset ¶ added in v1.5.0
func (c *ColorM) Reset()
Reset resets the ColorM as identity.
func (*ColorM) RotateHue ¶ added in v1.2.0
RotateHue rotates the hue. theta represents rotating angle in radian.
func (*ColorM) SetElement ¶
SetElement sets an element at (i, j).
type CompositeMode ¶ added in v1.3.0
type CompositeMode int
CompositeMode represents Porter-Duff composition mode.
const ( // Regular alpha blending // c_out = c_src + c_dst × (1 - α_src) CompositeModeSourceOver CompositeMode = CompositeMode(opengl.CompositeModeSourceOver) // c_out = 0 CompositeModeClear CompositeMode = CompositeMode(opengl.CompositeModeClear) // c_out = c_src CompositeModeCopy CompositeMode = CompositeMode(opengl.CompositeModeCopy) // c_out = c_dst CompositeModeDestination CompositeMode = CompositeMode(opengl.CompositeModeDestination) // c_out = c_src × (1 - α_dst) + c_dst CompositeModeDestinationOver CompositeMode = CompositeMode(opengl.CompositeModeDestinationOver) // c_out = c_src × α_dst CompositeModeSourceIn CompositeMode = CompositeMode(opengl.CompositeModeSourceIn) // c_out = c_dst × α_src CompositeModeDestinationIn CompositeMode = CompositeMode(opengl.CompositeModeDestinationIn) // c_out = c_src × (1 - α_dst) CompositeModeSourceOut CompositeMode = CompositeMode(opengl.CompositeModeSourceOut) // c_out = c_dst × (1 - α_src) CompositeModeDestinationOut CompositeMode = CompositeMode(opengl.CompositeModeDestinationOut) // c_out = c_src × α_dst + c_dst × (1 - α_src) CompositeModeSourceAtop CompositeMode = CompositeMode(opengl.CompositeModeSourceAtop) // c_out = c_src × (1 - α_dst) + c_dst × α_src CompositeModeDestinationAtop CompositeMode = CompositeMode(opengl.CompositeModeDestinationAtop) // c_out = c_src × (1 - α_dst) + c_dst × (1 - α_src) CompositeModeXor CompositeMode = CompositeMode(opengl.CompositeModeXor) // Sum of source and destination (a.k.a. 'plus' or 'additive') // c_out = c_src + c_dst CompositeModeLighter CompositeMode = CompositeMode(opengl.CompositeModeLighter) )
This name convention follows CSS compositing: https://drafts.fxtf.org/compositing-2/.
In the comments, c_src, c_dst and c_out represent alpha-premultiplied RGB values of source, destination and output respectively. α_src and α_dst represent alpha values of source and destination respectively.
type DrawImageOptions ¶
type DrawImageOptions struct { // SourceRect is the region of the source image to draw. // If SourceRect is nil, whole image is used. // // It is assured that texels out of the SourceRect are never used. // // Calling DrawImage copies the content of SourceRect pointer. This means that // even if the SourceRect value is modified after passed to DrawImage, // the result of DrawImage doen't change. // // op := &ebiten.DrawImageOptions{} // r := image.Rect(0, 0, 100, 100) // op.SourceRect = &r // dst.DrawImage(src, op) // r.Min.X = 10 // This doesn't affect the previous DrawImage. SourceRect *image.Rectangle // GeoM is a geometry matrix to draw. // The default (zero) value is identify, which draws the image at (0, 0). GeoM GeoM // ColorM is a color matrix to draw. // The default (zero) value is identity, which doesn't change any color. ColorM ColorM // CompositeMode is a composite mode to draw. // The default (zero) value is regular alpha blending. CompositeMode CompositeMode // Filter is a type of texture filter. // The default (zero) value is FilterDefault. // // Filter can also be specified at NewImage* functions, but // specifying filter at DrawImageOptions is recommended (as of 1.7.0-alpha). // // If both Filter specified at NewImage* and DrawImageOptions are FilterDefault, // FilterNearest is used. // If either is FilterDefault and the other is not, the latter is used. // Otherwise, Filter specified at DrawImageOptions is used. Filter Filter // Deprecated (as of 1.5.0-alpha): Use SourceRect instead. ImageParts ImageParts // Deprecated (as of 1.1.0-alpha): Use SourceRect instead. Parts []ImagePart }
A DrawImageOptions represents options to render an image on an image.
type DrawTrianglesOptions ¶ added in v1.8.0
type DrawTrianglesOptions struct { // ColorM is a color matrix to draw. // The default (zero) value is identity, which doesn't change any color. // ColorM is applied before vertex color scale is applied. ColorM ColorM // CompositeMode is a composite mode to draw. // The default (zero) value is regular alpha blending. CompositeMode CompositeMode // Filter is a type of texture filter. // The default (zero) value is FilterDefault. Filter Filter }
DrawTrianglesOptions represents options to render triangles on an image.
Note that this API is experimental.
type Filter ¶
type Filter int
Filter represents the type of texture filter to be used when an image is maginified or minified.
const ( // FilterDefault represents the default filter. FilterDefault Filter = Filter(graphics.FilterDefault) // FilterNearest represents nearest (crisp-edged) filter FilterNearest Filter = Filter(graphics.FilterNearest) // FilterLinear represents linear filter FilterLinear Filter = Filter(graphics.FilterLinear) )
type GamepadButton ¶ added in v1.2.0
type GamepadButton int
A GamepadButton represents a gamepad button.
const ( GamepadButton0 GamepadButton = GamepadButton(input.GamepadButton0) GamepadButton1 GamepadButton = GamepadButton(input.GamepadButton1) GamepadButton2 GamepadButton = GamepadButton(input.GamepadButton2) GamepadButton3 GamepadButton = GamepadButton(input.GamepadButton3) GamepadButton4 GamepadButton = GamepadButton(input.GamepadButton4) GamepadButton5 GamepadButton = GamepadButton(input.GamepadButton5) GamepadButton6 GamepadButton = GamepadButton(input.GamepadButton6) GamepadButton7 GamepadButton = GamepadButton(input.GamepadButton7) GamepadButton8 GamepadButton = GamepadButton(input.GamepadButton8) GamepadButton9 GamepadButton = GamepadButton(input.GamepadButton9) GamepadButton10 GamepadButton = GamepadButton(input.GamepadButton10) GamepadButton11 GamepadButton = GamepadButton(input.GamepadButton11) GamepadButton12 GamepadButton = GamepadButton(input.GamepadButton12) GamepadButton13 GamepadButton = GamepadButton(input.GamepadButton13) GamepadButton14 GamepadButton = GamepadButton(input.GamepadButton14) GamepadButton15 GamepadButton = GamepadButton(input.GamepadButton15) GamepadButton16 GamepadButton = GamepadButton(input.GamepadButton16) GamepadButton17 GamepadButton = GamepadButton(input.GamepadButton17) GamepadButton18 GamepadButton = GamepadButton(input.GamepadButton18) GamepadButton19 GamepadButton = GamepadButton(input.GamepadButton19) GamepadButton20 GamepadButton = GamepadButton(input.GamepadButton20) GamepadButton21 GamepadButton = GamepadButton(input.GamepadButton21) GamepadButton22 GamepadButton = GamepadButton(input.GamepadButton22) GamepadButton23 GamepadButton = GamepadButton(input.GamepadButton23) GamepadButton24 GamepadButton = GamepadButton(input.GamepadButton24) GamepadButton25 GamepadButton = GamepadButton(input.GamepadButton25) GamepadButton26 GamepadButton = GamepadButton(input.GamepadButton26) GamepadButton27 GamepadButton = GamepadButton(input.GamepadButton27) GamepadButton28 GamepadButton = GamepadButton(input.GamepadButton28) GamepadButton29 GamepadButton = GamepadButton(input.GamepadButton29) GamepadButton30 GamepadButton = GamepadButton(input.GamepadButton30) GamepadButton31 GamepadButton = GamepadButton(input.GamepadButton31) GamepadButtonMax GamepadButton = GamepadButton31 )
GamepadButtons
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 is deprecated as of 1.2.0-alpha. Use Translate instead.
func (*GeoM) Add ¶
Add is deprecated as of 1.5.0-alpha. Note that this doesn't make sense as an operation for affine matrices.
func (*GeoM) Apply ¶ added in v1.6.0
Apply pre-multiplies a vector (x, y, 1) by the matrix. In other words, Apply calculates GeoM * (x, y, 1)^T. The return value is x and y values of the result vector.
func (*GeoM) Concat ¶
Concat multiplies a geometry matrix with the other geometry matrix. This is same as muptiplying the matrix other and the matrix g in this order.
func (*GeoM) Invert ¶ added in v1.7.0
func (g *GeoM) Invert()
Invert inverts the matrix. If g is not invertible, Invert panics.
func (*GeoM) IsInvertible ¶ added in v1.7.0
IsInvertible returns a boolean value indicating whether the matrix g is invertible or not.
func (*GeoM) SetElement ¶
SetElement sets an element at (i, j).
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents a rectangle set of pixels. The pixel format is alpha-premultiplied RGBA. Image implements image.Image.
Functions of Image never returns error as of 1.5.0-alpha, and error values are always nil.
func NewImage ¶
NewImage returns an empty image.
If width or height is less than 1 or more than device-dependent maximum size, NewImage panics.
filter argument is just for backward compatibility. If you are not sure, specify FilterDefault.
Error returned by NewImage is always nil as of 1.5.0-alpha.
func NewImageFromImage ¶
NewImageFromImage creates a new image with the given image (source).
If source's width or height is less than 1 or more than device-dependent maximum size, NewImageFromImage panics.
filter argument is just for backward compatibility. If you are not sure, specify FilterDefault.
Error returned by NewImageFromImage is always nil as of 1.5.0-alpha.
func (*Image) At ¶
At returns the color of the image at (x, y).
At loads pixels from GPU to system memory if necessary, which means that At can be slow.
At always returns a transparent color if the image is disposed.
Note that important logic should not rely on At result since At might include a very slight error on some machines.
At can't be called before the main loop (ebiten.Run) starts (as of version 1.4.0-alpha).
func (*Image) Clear ¶
Clear resets the pixels of the image into 0.
When the image is disposed, Clear does nothing.
Clear always returns nil as of 1.5.0-alpha.
func (*Image) ColorModel ¶
ColorModel returns the color model of the image.
func (*Image) Dispose ¶ added in v1.2.0
Dispose disposes the image data. After disposing, most of image functions do nothing and returns meaningless values.
Dispose is useful to save memory.
When the image is disposed, Dipose does nothing.
Dipose always return nil as of 1.5.0-alpha.
func (*Image) DrawImage ¶
func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error
DrawImage draws the given image on the image i.
DrawImage accepts the options. For details, see the document of DrawImageOptions.
DrawImage determines the part to draw, then DrawImage applies the geometry matrix and the color matrix.
For drawing, the pixels of the argument image at the time of this call is adopted. Even if the argument image is mutated after this call, the drawing result is never affected.
When the image i is disposed, DrawImage does nothing. When the given image img is disposed, DrawImage panics.
When the given image is as same as i, DrawImage panics.
DrawImage works more efficiently as batches when the successive calls of DrawImages satisfies the below conditions:
- All render targets are same (A in A.DrawImage(B, op))
- All render sources are same (B in A.DrawImage(B, op))
- This is not a strong request since different images might share a same inner OpenGL texture in high possibility. This is not 100%, so using the same render source is safer.
- All ColorM values are same, or all the ColorM have only 'scale' operations
- All CompositeMode values are same
- All Filter values are same
For more performance tips, see https://github.com/hajimehoshi/ebiten/wiki/Performance-Tips.
DrawImage always returns nil as of 1.5.0-alpha.
func (*Image) DrawTriangles ¶ added in v1.8.0
func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, options *DrawTrianglesOptions)
DrawTriangles draws a triangle with the specified vertices and their indices.
If len(indices) is not multiple of 3, DrawTriangles panics.
The rule in which DrawTriangles works effectively is same as DrawImage's.
In contrast to DrawImage, DrawTriangles doesn't care source image edges. This means that you might need to add 1px gap on a source region when you render an image by DrawTriangles. Note that Ebiten creates texture atlases internally, so you still have to care this even when you render a single image.
Note that this API is experimental.
func (*Image) Fill ¶
Fill fills the image with a solid color.
When the image is disposed, Fill does nothing.
Fill always returns nil as of 1.5.0-alpha.
func (*Image) ReplacePixels ¶ added in v1.2.0
ReplacePixels replaces the pixels of the image with p.
The given p must represent RGBA pre-multiplied alpha values. len(p) must equal to 4 * (image width) * (image height).
ReplacePixels may be slow (as for implementation, this calls glTexSubImage2D).
When len(p) is not appropriate, ReplacePixels panics.
When the image is disposed, ReplacePixels does nothing.
ReplacePixels always returns nil as of 1.5.0-alpha.
type ImageParts ¶ added in v1.1.0
type ImageParts interface { Len() int Dst(i int) (x0, y0, x1, y1 int) Src(i int) (x0, y0, x1, y1 int) }
An ImageParts is deprecated (as of 1.5.0-alpha): Use SourceRect instead.
type Key ¶
type Key int
A Key represents a keyboard key. These keys represent pysical keys of US keyboard. For example, KeyQ represents Q key on US keyboards and ' (quote) key on Dvorak keyboards.
const ( Key0 Key = Key(input.Key0) Key1 Key = Key(input.Key1) Key2 Key = Key(input.Key2) Key3 Key = Key(input.Key3) Key4 Key = Key(input.Key4) Key5 Key = Key(input.Key5) Key6 Key = Key(input.Key6) Key7 Key = Key(input.Key7) Key8 Key = Key(input.Key8) Key9 Key = Key(input.Key9) KeyA Key = Key(input.KeyA) KeyB Key = Key(input.KeyB) KeyC Key = Key(input.KeyC) KeyD Key = Key(input.KeyD) KeyE Key = Key(input.KeyE) KeyF Key = Key(input.KeyF) KeyG Key = Key(input.KeyG) KeyH Key = Key(input.KeyH) KeyI Key = Key(input.KeyI) KeyJ Key = Key(input.KeyJ) KeyK Key = Key(input.KeyK) KeyL Key = Key(input.KeyL) KeyM Key = Key(input.KeyM) KeyN Key = Key(input.KeyN) KeyO Key = Key(input.KeyO) KeyP Key = Key(input.KeyP) KeyQ Key = Key(input.KeyQ) KeyR Key = Key(input.KeyR) KeyS Key = Key(input.KeyS) KeyT Key = Key(input.KeyT) KeyU Key = Key(input.KeyU) KeyV Key = Key(input.KeyV) KeyW Key = Key(input.KeyW) KeyX Key = Key(input.KeyX) KeyY Key = Key(input.KeyY) KeyZ Key = Key(input.KeyZ) KeyAlt Key = Key(input.KeyAlt) KeyApostrophe Key = Key(input.KeyApostrophe) KeyBackslash Key = Key(input.KeyBackslash) KeyBackspace Key = Key(input.KeyBackspace) KeyCapsLock Key = Key(input.KeyCapsLock) KeyComma Key = Key(input.KeyComma) KeyControl Key = Key(input.KeyControl) KeyDelete Key = Key(input.KeyDelete) KeyDown Key = Key(input.KeyDown) KeyEnd Key = Key(input.KeyEnd) KeyEnter Key = Key(input.KeyEnter) KeyEqual Key = Key(input.KeyEqual) KeyEscape Key = Key(input.KeyEscape) KeyF1 Key = Key(input.KeyF1) KeyF2 Key = Key(input.KeyF2) KeyF3 Key = Key(input.KeyF3) KeyF4 Key = Key(input.KeyF4) KeyF5 Key = Key(input.KeyF5) KeyF6 Key = Key(input.KeyF6) KeyF7 Key = Key(input.KeyF7) KeyF8 Key = Key(input.KeyF8) KeyF9 Key = Key(input.KeyF9) KeyF10 Key = Key(input.KeyF10) KeyF11 Key = Key(input.KeyF11) KeyF12 Key = Key(input.KeyF12) KeyGraveAccent Key = Key(input.KeyGraveAccent) KeyHome Key = Key(input.KeyHome) KeyInsert Key = Key(input.KeyInsert) KeyKP0 Key = Key(input.KeyKP0) KeyKP1 Key = Key(input.KeyKP1) KeyKP2 Key = Key(input.KeyKP2) KeyKP3 Key = Key(input.KeyKP3) KeyKP4 Key = Key(input.KeyKP4) KeyKP5 Key = Key(input.KeyKP5) KeyKP6 Key = Key(input.KeyKP6) KeyKP7 Key = Key(input.KeyKP7) KeyKP8 Key = Key(input.KeyKP8) KeyKP9 Key = Key(input.KeyKP9) KeyKPAdd Key = Key(input.KeyKPAdd) KeyKPDecimal Key = Key(input.KeyKPDecimal) KeyKPDivide Key = Key(input.KeyKPDivide) KeyKPEnter Key = Key(input.KeyKPEnter) KeyKPEqual Key = Key(input.KeyKPEqual) KeyKPMultiply Key = Key(input.KeyKPMultiply) KeyKPSubtract Key = Key(input.KeyKPSubtract) KeyLeft Key = Key(input.KeyLeft) KeyLeftBracket Key = Key(input.KeyLeftBracket) KeyMenu Key = Key(input.KeyMenu) KeyMinus Key = Key(input.KeyMinus) KeyNumLock Key = Key(input.KeyNumLock) KeyPageDown Key = Key(input.KeyPageDown) KeyPageUp Key = Key(input.KeyPageUp) KeyPause Key = Key(input.KeyPause) KeyPeriod Key = Key(input.KeyPeriod) KeyPrintScreen Key = Key(input.KeyPrintScreen) KeyRight Key = Key(input.KeyRight) KeyRightBracket Key = Key(input.KeyRightBracket) KeyScrollLock Key = Key(input.KeyScrollLock) KeySemicolon Key = Key(input.KeySemicolon) KeyShift Key = Key(input.KeyShift) KeySlash Key = Key(input.KeySlash) KeySpace Key = Key(input.KeySpace) KeyTab Key = Key(input.KeyTab) KeyUp Key = Key(input.KeyUp) KeyMax Key = KeyUp )
Keys.
type MouseButton ¶
type MouseButton int
A MouseButton represents a mouse button.
const ( MouseButtonLeft MouseButton = MouseButton(input.MouseButtonLeft) MouseButtonRight MouseButton = MouseButton(input.MouseButtonRight) MouseButtonMiddle MouseButton = MouseButton(input.MouseButtonMiddle) )
MouseButtons
type Touch ¶ added in v1.4.0
type Touch interface { // ID returns an identifier for one stroke. ID() int // Position returns the position of the touch. Position() (x, y int) }
Touch is deprecated as of 1.7.0. Use TouchPosition instead.
type Vertex ¶ added in v1.8.0
type Vertex struct { // DstX and DstY represents a point on a destination image. DstX float32 DstY float32 // SrcX and SrcY represents a point on a source image. SrcX float32 SrcY float32 // ColorR/ColorG/ColorB/ColorA represents color scaling values. // 1 means the original source image color is used. // 0 means a transparent color is used. ColorR float32 ColorG float32 ColorB float32 ColorA float32 }
Vertex represents a vertex passed to DrawTriangles.
Note that this API is experimental.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package audio provides audio players.
|
Package audio provides audio players. |
mp3
Package mp3 provides MP3 decoder.
|
Package mp3 provides MP3 decoder. |
vorbis
Package vorbis provides Ogg/Vorbis decoder.
|
Package vorbis provides Ogg/Vorbis decoder. |
wav
Package wav provides WAV (RIFF) decoder.
|
Package wav provides WAV (RIFF) decoder. |
Package ebitenutil provides utility functions for Ebiten.
|
Package ebitenutil provides utility functions for Ebiten. |
examples
|
|
Package inpututil provides utility functions of input like keyboard or mouse.
|
Package inpututil provides utility functions of input like keyboard or mouse. |
internal
|
|
clock
Package clock manages game timers.
|
Package clock manages game timers. |
graphics
Package graphics represents a low layer for graphics using OpenGL.
|
Package graphics represents a low layer for graphics using OpenGL. |
packing
Package packing offers a packing algorithm in 2D space.
|
Package packing offers a packing algorithm in 2D space. |
png
Package png implements a PNG image decoder and encoder.
|
Package png implements a PNG image decoder and encoder. |
restorable
Package restorable offers an Image struct that stores image commands and restores its pixel data from the commands when context lost happens.
|
Package restorable offers an Image struct that stores image commands and restores its pixel data from the commands when context lost happens. |
testflock
Package testflock provides a lock for testing.
|
Package testflock provides a lock for testing. |
Package mobile provides functions for mobile platforms (Android and iOS).
|
Package mobile provides functions for mobile platforms (Android and iOS). |
Package text offers functions to draw texts on an Ebiten's image.
|
Package text offers functions to draw texts on an Ebiten's image. |