mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-30 12:34:28 +01:00
Updated Cheat Sheet (markdown)
parent
fabe5203f1
commit
fd1cb84a38
@ -2,19 +2,79 @@ This cheat sheet describes the essential APIs that are commonly used. For the co
|
||||
|
||||
# General
|
||||
|
||||
## `Run`
|
||||
## `ebiten.Run`
|
||||
|
||||
```go
|
||||
func Run(f func(*Image) error, width, height int, scale float64, title string) error
|
||||
```
|
||||
|
||||
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`).
|
||||
`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`).
|
||||
|
||||
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`.
|
||||
|
||||
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.
|
||||
`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.
|
||||
|
||||
Don't call Run twice or more in one process.
|
||||
|
||||
# Graphics
|
||||
|
||||
## `ebiten.Image`
|
||||
|
||||
```go
|
||||
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`](https://golang.org/pkg/image/#Image).
|
||||
|
||||
### `ebiten.NewImage`
|
||||
|
||||
```go
|
||||
func NewImage(width, height int, filter Filter) (*Image, error)
|
||||
```
|
||||
|
||||
`NewImage` returns an empty image. `NewImage` always returns nil error (so you can ignore that).
|
||||
|
||||
`filter` argument is just for backward compatibility. If you are not sure, specify `FilterDefault`.
|
||||
|
||||
### `ebiten.NewImageFromImage`
|
||||
|
||||
```go
|
||||
func NewImageFromImage(source image.Image, filter Filter) (*Image, error)
|
||||
```
|
||||
|
||||
`NewImageFromImage` creates a new image with the given image (source). `NewImageFromImage` always returns nil error.
|
||||
|
||||
`filter` argument is just for backward compatibility. If you are not sure, specify FilterDefault.
|
||||
|
||||
### `(*ebiten.Image).Clear`
|
||||
|
||||
```go
|
||||
func (i *Image) Clear() error
|
||||
```
|
||||
|
||||
`Clear` resets the pixels of the image into 0.
|
||||
|
||||
`Clear` always returns nil.
|
||||
|
||||
### `(*ebiten.Image).Fill`
|
||||
|
||||
```go
|
||||
func (i *Image) Fill(clr color.Color) error
|
||||
```
|
||||
|
||||
`Fill` fills the image with a solid color.
|
||||
|
||||
`Fill` always returns nil.
|
||||
|
||||
### `(*ebiten.Image).Size`
|
||||
|
||||
```go
|
||||
func (i *Image) Size() (width, height int)
|
||||
```
|
||||
|
||||
`Size` returns the size of the image.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user