Documentation ¶
Index ¶
- Constants
- Variables
- func DrawAnime(screen *ebiten.Image, anim *Animation, x, y, rot, sx, sy, ox, oy float64)
- func DrawAnimeWithOpts(screen *ebiten.Image, anim *Animation, opts *DrawOptions, ...)
- func DrawSprite(screen *ebiten.Image, spr *Sprite, index int, ...)
- func DrawSpriteWithOpts(screen *ebiten.Image, spr *Sprite, index int, opts *DrawOptions, ...)
- func Nop(anim *Animation, loops int)
- func Pause(anim *Animation, loops int)
- func PauseAtEnd(anim *Animation, loops int)
- func PauseAtStart(anim *Animation, loops int)
- type Animation
- func (anim *Animation) Clone() *Animation
- func (anim *Animation) Draw(screen *ebiten.Image, opts *DrawOptions)
- func (anim *Animation) DrawWithShader(screen *ebiten.Image, opts *DrawOptions, shaderOpts *ShaderOptions)
- func (anim *Animation) Durations() []time.Duration
- func (anim *Animation) GoToFrame(position int)
- func (anim *Animation) H() int
- func (anim *Animation) IsEnd() bool
- func (anim *Animation) Pause()
- func (anim *Animation) PauseAtEnd()
- func (anim *Animation) PauseAtStart()
- func (anim *Animation) Position() int
- func (anim *Animation) Resume()
- func (anim *Animation) SetDurations(durations interface{})
- func (anim *Animation) SetOnLoop(onLoop OnLoop)
- func (anim *Animation) Size() (int, int)
- func (anim *Animation) Sprite() *Sprite
- func (anim *Animation) Status() Status
- func (anim *Animation) Timer() time.Duration
- func (anim *Animation) TotalDuration() time.Duration
- func (anim *Animation) Update()
- func (anim *Animation) UpdateWithDelta(elapsedTime time.Duration)
- func (anim *Animation) W() int
- type DrawOptions
- func (drawOpts *DrawOptions) Reset()
- func (drawOpts *DrawOptions) ResetValues(x, y, rot, sx, sy, ox, oy float64)
- func (drawOpts *DrawOptions) SetOrigin(x, y float64)
- func (drawOpts *DrawOptions) SetPos(x, y float64)
- func (drawOpts *DrawOptions) SetRot(r float64)
- func (drawOpts *DrawOptions) SetScale(x, y float64)
- type Grid
- type OnLoop
- type ShaderOptions
- type Sprite
- func (spr *Sprite) Clone() *Sprite
- func (spr *Sprite) Draw(screen *ebiten.Image, index int, opts *DrawOptions)
- func (spr *Sprite) DrawWithShader(screen *ebiten.Image, index int, opts *DrawOptions, shaderOpts *ShaderOptions)
- func (spr *Sprite) FlipH()
- func (spr *Sprite) FlipV()
- func (spr *Sprite) H() int
- func (spr *Sprite) Height() int
- func (spr *Sprite) IsEnd(index int) bool
- func (spr *Sprite) Length() int
- func (spr *Sprite) LoopIndex(index int) int
- func (spr *Sprite) RandomIndex() int
- func (spr *Sprite) SetFlipH(flipH bool)
- func (spr *Sprite) SetFlipV(flipV bool)
- func (spr *Sprite) Size() (int, int)
- func (spr *Sprite) W() int
- func (spr *Sprite) Width() int
- type SpriteSize
- type SpriteSizeF
- type Status
Constants ¶
const ( Playing = iota Paused )
Variables ¶
var DefaultDelta = time.Millisecond * 16
Functions ¶
func DrawAnimeWithOpts ¶ added in v2.0.11
func DrawAnimeWithOpts(screen *ebiten.Image, anim *Animation, opts *DrawOptions, shaderOpts *ShaderOptions)
DrawAnimeWithOpts draws an anime to the screen.
func DrawSprite ¶ added in v2.0.8
DrawSprite draws a sprite to the screen.
func DrawSpriteWithOpts ¶ added in v2.0.11
func DrawSpriteWithOpts(screen *ebiten.Image, spr *Sprite, index int, opts *DrawOptions, shaderOpts *ShaderOptions)
DrawSpriteWithOpts draws a sprite to the screen.
func PauseAtEnd ¶
PauseAtEnd pauses the animation and set the position to the last frame.
func PauseAtStart ¶
PauseAtStart pauses the animation and set the position to the first frame.
Types ¶
type Animation ¶
type Animation struct {
// contains filtered or unexported fields
}
Animation represents an animation created from specified frames and an *ebiten.Image
func New ¶ added in v2.1.0
func New(img *ebiten.Image, frames []*image.Rectangle, durations interface{}, onLoop ...OnLoop) *Animation
New creates a new animation from the specified image
func NewAnimation ¶
NewAnimation returns a new animation object
durations is a time.Duration or a []time.Duration or a map[string]time.Duration. When it's a time.Duration, it represents the duration of all frames in the animation. When it's a []time.Duration, it can represent different durations for different frames. You can specify durations for all frames individually, like this: []time.Duration { 100 * time.Millisecond, 100 * time.Millisecond } or you can specify durations for ranges of frames: map[string]time.Duration { "1-2": 100 * time.Millisecond, "3-5": 200 * time.Millisecond }.
func (*Animation) Draw ¶
func (anim *Animation) Draw(screen *ebiten.Image, opts *DrawOptions)
Draw draws the animation with the specified option parameters.
func (*Animation) DrawWithShader ¶
func (anim *Animation) DrawWithShader(screen *ebiten.Image, opts *DrawOptions, shaderOpts *ShaderOptions)
DrawWithShader draws the animation with the specified option parameters.
func (*Animation) GoToFrame ¶
GoToFrame sets the position of the animation and sets the timer at the start of the frame.
func (*Animation) PauseAtEnd ¶
func (anim *Animation) PauseAtEnd()
PauseAtEnd pauses the animation and set the position to the last frame.
func (*Animation) PauseAtStart ¶
func (anim *Animation) PauseAtStart()
PauseAtStart pauses the animation and set the position to the first frame.
func (*Animation) Position ¶
Position returns the current position of the frame. The position counts from 1 (not 0).
func (*Animation) SetDurations ¶ added in v2.0.18
func (anim *Animation) SetDurations(durations interface{})
SetDurations sets the durations of the animation.
func (*Animation) SetOnLoop ¶ added in v2.1.28
SetOnLoop sets the callback function which representing
func (*Animation) TotalDuration ¶
TotalDuration returns the total duration of the animation.
func (*Animation) UpdateWithDelta ¶ added in v2.1.24
UpdateWithDelta updates the animation with the specified delta.
type DrawOptions ¶
type DrawOptions struct {
X, Y float64
Rotate float64
ScaleX, ScaleY float64
OriginX, OriginY float64
ColorM ebiten.ColorM
CompositeMode ebiten.CompositeMode
}
DrawOptions represents the option for Sprite.Draw(). For shortcut, DrawOpts() function can be used.
func DrawOpts ¶
func DrawOpts(x, y float64, args ...float64) *DrawOptions
DrawOpts returns DrawOptions pointer with specified settings. The paramters are x, y, rotate (in radian), scaleX, scaleY originX, originY. If scaleX and ScaleY is not specified the default value will be 1.0, 1.0. If OriginX and OriginY is not specified the default value will be 0, 0
func (*DrawOptions) Reset ¶ added in v2.0.9
func (drawOpts *DrawOptions) Reset()
Reset resets the DrawOptions to default values.
func (*DrawOptions) ResetValues ¶ added in v2.0.10
func (drawOpts *DrawOptions) ResetValues(x, y, rot, sx, sy, ox, oy float64)
ResetValues resets the DrawOptions to default values
func (*DrawOptions) SetOrigin ¶ added in v2.0.6
func (drawOpts *DrawOptions) SetOrigin(x, y float64)
SetOrigin sets the origin of the sprite.
func (*DrawOptions) SetPos ¶ added in v2.0.6
func (drawOpts *DrawOptions) SetPos(x, y float64)
SetPos sets the position of the sprite.
func (*DrawOptions) SetRot ¶ added in v2.0.7
func (drawOpts *DrawOptions) SetRot(r float64)
SetRotate sets the rotation of the sprite.
func (*DrawOptions) SetScale ¶ added in v2.0.6
func (drawOpts *DrawOptions) SetScale(x, y float64)
SetScale sets the scale of the sprite.
type Grid ¶
type Grid struct {
// contains filtered or unexported fields
}
Grid represents a grid
func NewGrid ¶
NewGrid returns a new grid with specified frame size, image size, and offsets (left, top).
Grids have only one purpose: To build groups of quads of the same size as easily as possible.
They need to know only 2 things: the size of each frame and the size of the image they will be applied to.
Grids are just a convenient way of getting frames from a sprite. Frames are assumed to be distributed in rows and columns. Frame 1,1 is the one in the first row, first column.
func (*Grid) GetFrames ¶
GetFrames accepts an arbitrary number of parameters. They can be either numbers or strings.
Each two numbers are interpreted as quad coordinates in the format (column, row). This way, grid:getFrames(3,4) will return the frame in column 3, row 4 of the grid.
There can be more than just two: grid:getFrames(1,1, 1,2, 1,3) will return the frames in {1,1}, {1,2} and {1,3} respectively.
type OnLoop ¶
OnLoop is callback function which representing one of the animation methods. it will be called every time an animation "loops".
It will have two parameters: the animation instance, and how many loops have been elapsed.
The value would be Nop (No operation) if there's nothing to do except for looping the animation.
The most usual value (apart from none) is the string 'pauseAtEnd'. It will make the animation loop once and then pause and stop on the last frame.
type ShaderOptions ¶
type ShaderOptions struct { Uniforms map[string]interface{} Shader *ebiten.Shader Images [3]*ebiten.Image }
ShaderOptions represents the option for Sprite.DrawWithShader()
type Sprite ¶
type Sprite struct {
// contains filtered or unexported fields
}
Sprite is a sprite that can be drawn to the screen. It can be animated by changing the current frame.
func (*Sprite) Draw ¶
func (spr *Sprite) Draw(screen *ebiten.Image, index int, opts *DrawOptions)
Draw draws the current frame with the specified options.
func (*Sprite) DrawWithShader ¶
func (spr *Sprite) DrawWithShader(screen *ebiten.Image, index int, opts *DrawOptions, shaderOpts *ShaderOptions)
DrawWithShader draws the current frame with the specified options.
func (*Sprite) RandomIndex ¶ added in v2.0.14
RandomIndex returns random index of the sprite
type SpriteSize ¶
type SpriteSize struct {
W, H int
}
type SpriteSizeF ¶ added in v2.0.4
type SpriteSizeF struct {
W, H float64
}