shake

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package shake provides methods for rapidly shifting graphical components' positions

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultShaker is the global default shaker, used when shake.Screen or shake.Shake are called.
	DefaultShaker = &Shaker{
		Random:        false,
		Magnitude:     floatgeom.Point2{3.0, 3.0},
		Delay:         30 * time.Millisecond,
		ResetPosition: true,
	}
)

Functions

func Screen

func Screen(ctx *scene.Context, dur time.Duration)

Screen shakes the screen that the context controls for the given duration. It uses the settings in DefaultShaker to determine the quality of the shake.

func Shake

func Shake(sp ShiftPoser, dur time.Duration)

Shake shakes a ShiftPoser for the given duration. It uses the settings in DefaultShaker to determine the quality of the shake.

Types

type Shaker

type Shaker struct {
	Magnitude floatgeom.Point2
	Delay     time.Duration
	Random    bool
	// ResetPosition determines whether the shaken entity will be reset back to its original position
	// after shaking is complete. True by default.
	ResetPosition bool
}

A Shaker knows how to shake something by a (or up to a) given magnitude. If Random is true, the Shaker will shake up to the (negative or positive) magnitude of each the X and Y axes. Otherwise, it will oscillate between negative magnitude and positive magnitude.

func (*Shaker) Shake

func (sk *Shaker) Shake(sp ShiftPoser, dur time.Duration)

Shake shakes a ShiftPoser for the given duration.

func (*Shaker) ShakeContext

func (sk *Shaker) ShakeContext(ctx context.Context, sp ShiftPoser, dur time.Duration)

ShakeContext shakes a ShiftPoser for the given duration or until the context is done, whichever comes first.

func (*Shaker) ShakeScreen

func (sk *Shaker) ShakeScreen(ctx *scene.Context, dur time.Duration)

ShakeScreen shakes the screen that the context controls for the given duration.

type ShiftPoser

type ShiftPoser interface {
	ShiftPos(x, y float64)
}

A ShiftPoser can have its position shifted by an x,y pair

Jump to

Keyboard shortcuts

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