Updated Cheat Sheet (markdown)

Hajime Hoshi 2018-10-12 23:58:23 +09:00
parent fd1cb84a38
commit 5b7434e244

@ -48,7 +48,7 @@ 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.
`filter` argument is just for backward compatibility. If you are not sure, specify `FilterDefault`.
### `(*ebiten.Image).Clear`
@ -78,3 +78,94 @@ func (i *Image) Size() (width, height int)
`Size` returns the size of the image.
### `(*ebiten.Image).DrawImage`
```go
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 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 [[Performance Tips]].
`DrawImage` always returns nil.
## `ebiten.DrawImageOptions`
```go
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 Filter
}
```
`DrawImageOptions` represents options to render an image on an image.
## `ebiten.Filter`
```go
type Filter int
```
Filter represents the type of texture filter to be used when an image is maginified or minified.
```go
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)
)
```