anim

package
v0.0.0-...-567232d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Playing = iota
	Paused
)
View Source
const Dur24FPS time.Duration = 41 * time.Millisecond

Variables

View Source
var DefaultDelta = time.Millisecond * 16
View Source
var ErrNotFound error = errors.New("image not found")

Functions

func GetImagesByIndicesFromFS

func GetImagesByIndicesFromFS(fsys fs.FS, path string, prefix string, indices []int) ([]*ebiten.Image, error)

GetImagesByIndicesFromFS is basically addByIndices in HaxeFlixel. It gets images by indices from the filesystem and returns them.

func GetImagesByPrefixFromFS

func GetImagesByPrefixFromFS(fsys fs.FS, path string, prefix string) ([]*ebiten.Image, error)

GetImagesByPrefixFromFS is basically addByPrefix in HaxeFlixel. It gets images by prefix from the filesystem and returns them.

func MustGetImagesByIndicesFromFS

func MustGetImagesByIndicesFromFS(fsys fs.FS, path string, prefix string, indices []int) []*ebiten.Image

MustGetImagesByIndicesFromFS simply calls GetImagesByIndicesFromFS and panics if an error occurs.

func MustGetImagesByPrefixFromFS

func MustGetImagesByPrefixFromFS(fsys fs.FS, path string, prefix string) []*ebiten.Image

MustGetImagesByPrefixFromFS simply calls GetImagesByPrefixFromFS and panics if an error occurs.

func Nop

func Nop(anim *Animation, loops int)

Nop does nothing.

func Pause

func Pause(anim *Animation, loops int)

Pause pauses the animation on loop finished.

func PauseAtEnd

func PauseAtEnd(anim *Animation, loops int)

PauseAtEnd pauses the animation and set the position to the last frame.

func PauseAtStart

func PauseAtStart(anim *Animation, loops int)

PauseAtStart pauses the animation and set the position to the first frame.

Types

type AnimController

type AnimController struct {
	// contains filtered or unexported fields
}

func NewAnimController

func NewAnimController() *AnimController

func (*AnimController) Draw

func (ac *AnimController) Draw(img *ebiten.Image, op *ebiten.DrawImageOptions)

func (*AnimController) GetAnim

func (ac *AnimController) GetAnim(name string) *Animation

func (*AnimController) Play

func (ac *AnimController) Play(name string)

func (*AnimController) SetAnim

func (ac *AnimController) SetAnim(name string, anim *Animation)

func (*AnimController) UpdateWithDelta

func (ac *AnimController) UpdateWithDelta(dt float64)

type Animation

type Animation struct {
	// contains filtered or unexported fields
}

Animation represents an animation created from specified frames and an *ebiten.Image

func NewAnimation

func NewAnimation(frames []*ebiten.Image, durations interface{}, onLoop ...OnLoop) *Animation

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) Clone

func (anim *Animation) Clone() *Animation

Clone return a copied animation object.

func (*Animation) Draw

func (anim *Animation) Draw(screen *ebiten.Image, op *ebiten.DrawImageOptions)

Draw draws the animation with the specified option parameters.

func (*Animation) Durations

func (anim *Animation) Durations() []time.Duration

Duration returns the current durations of each frames.

func (*Animation) GoToFrame

func (anim *Animation) GoToFrame(position int)

GoToFrame sets the position of the animation and sets the timer at the start of the frame.

func (*Animation) IsEnd

func (anim *Animation) IsEnd() bool

func (*Animation) Pause

func (anim *Animation) Pause()

Pause pauses the animation.

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

func (anim *Animation) Position() int

Position returns the current position of the frame. The position counts from 1 (not 0).

func (*Animation) Resume

func (anim *Animation) Resume()

Resume resumes the animation

func (*Animation) SetDurations

func (anim *Animation) SetDurations(durations interface{})

SetDurations sets the durations of the animation.

func (*Animation) SetOnLoop

func (anim *Animation) SetOnLoop(onLoop OnLoop)

SetOnLoop sets the callback function which representing

func (*Animation) Status

func (anim *Animation) Status() Status

Status returns the status of the animation.

func (*Animation) Timer

func (anim *Animation) Timer() time.Duration

Timer returns the current accumulated times of current frame.

func (*Animation) TotalDuration

func (anim *Animation) TotalDuration() time.Duration

TotalDuration returns the total duration of the animation.

func (*Animation) Update

func (anim *Animation) Update()

Update updates the animation.

func (*Animation) UpdateWithDelta

func (anim *Animation) UpdateWithDelta(elapsedTime time.Duration)

UpdateWithDelta updates the animation with the specified delta.

type OnLoop

type OnLoop func(anim *Animation, loops int)

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 Status

type Status int

Status represents the animation status.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL