tween

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tween provides caller-advanced Tween playheads for duration-based transitions.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tween

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

Tween tracks elapsed time and applies an easing curve to normalized progress. Pass its progress to geom.Lerp or geom.Vector2.Lerp to interpolate values. The caller chooses the clock by supplying elapsed time to Tween.Update.

Copying a Tween copies its playback state. Copies share the curve and any state it captures; the curve should be pure so repeated reads agree.

The zero value is uninitialized: Update returns an error, Progress returns 0, IsComplete returns false, and Reset leaves it uninitialized.

Example
tween, err := NewTween(time.Second, geom.EaseInQuad)
if err != nil {
	fmt.Println(err)
	return
}
weight, err := tween.Update(500 * time.Millisecond)
if err != nil {
	fmt.Println(err)
	return
}
fmt.Println(geom.Lerp(0, 100, weight))
fmt.Println(tween.IsComplete())
Output:
25
false

func NewTween

func NewTween(duration time.Duration, ease geom.Ease) (Tween, error)

NewTween returns a Tween with the given duration and easing curve. It returns an error if duration is non-positive. A nil curve means geom.EaseLinear.

func (*Tween) IsComplete

func (t *Tween) IsComplete() bool

IsComplete reports whether the tween has reached its duration. Completion remains true until Tween.Reset, regardless of the curve's output.

func (*Tween) Progress

func (t *Tween) Progress() float64

Progress returns the current eased progress of the tween without advancing it. It evaluates the curve at elapsed time divided by duration. The result is not clamped, including at completion.

func (*Tween) Reset

func (t *Tween) Reset()

Reset restarts the tween without changing its duration or curve.

func (*Tween) Update

func (t *Tween) Update(delta time.Duration) (float64, error)

Update advances the tween by delta and returns Tween.Progress. Advancement stops at the duration and discards excess time. A negative delta returns an error without changing the tween.

Jump to

Keyboard shortcuts

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