anim

package
v0.0.0-...-f24390b Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package anim implements animations. It's a modified version of https://github.com/yohamta/ganim8 .

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

Functions

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, pt image.Point)

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

func (ac *AnimController) Update()

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, pt image.Point)

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.

Directories

Path Synopsis
Package animhcl allows loading from external HCL files (see `assets/images` for examples).
Package animhcl allows loading from external HCL files (see `assets/images` for examples).

Jump to

Keyboard shortcuts

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