sprites

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2023 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Left HorizonalAlignment = func(x float64, width float64) float64 {
		return x
	}

	Center HorizonalAlignment = func(x float64, width float64) float64 {
		return x - (width / 2)
	}

	Right HorizonalAlignment = func(x float64, width float64) float64 {
		return x - width
	}

	Top VerticalAlignment = func(y float64, height float64) float64 {
		return y
	}

	Middle VerticalAlignment = func(y float64, height float64) float64 {
		return y - (height / 2)
	}

	Bottom VerticalAlignment = func(y float64, height float64) float64 {
		return y - height
	}

	TopLeft Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Left(x, width), Top(y, height)
	}

	TopCenter Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Center(x, width), Top(y, height)
	}

	TopRight Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Right(x, width), Top(y, height)
	}

	MiddleLeft Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Left(x, width), Middle(y, height)
	}

	MiddleCenter Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Center(x, width), Middle(y, height)
	}

	MiddleRight Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Right(x, width), Middle(y, height)
	}

	BottomLeft Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Left(x, width), Bottom(y, height)
	}

	BottomMiddle Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Middle(x, width), Bottom(y, height)
	}

	BottomRight Alignment = func(x float64, y float64, width float64, height float64) (float64, float64) {
		return Right(x, width), Bottom(y, height)
	}
)

Functions

This section is empty.

Types

type Alignment

type Alignment func(x float64, y float64, width float64, height float64) (float64, float64)

type Animation

type Animation struct {
	// Frames is a slice of this animation's individual frames.
	Frames []*Frame

	// Direction is the direction the animation will be played (forward/reverse).
	Direction Direction
}

Animation objects contain the actual images and metadata used by sprites. Sprites are responsible for maintaining their own state, such as which frame of an animation is currently displayed.

type Direction

type Direction string

Direction a possible animation direction (forward/reverse).

type Frame

type Frame struct {
	// Image is the frame's image.
	Image *ebiten.Image

	// Duration is the duration the frame is displayed before progressing to the next frame.
	Duration time.Duration
}

Frame represents a single animation frame.

type HorizonalAlignment

type HorizonalAlignment func(x float64, width float64) float64

type Sprite

type Sprite struct {
	X      float64
	Y      float64
	Origin Alignment
	Scale  float64
	Speed  float64
	Angle  float64

	Visible bool
	// contains filtered or unexported fields
}

func NewSprite

func NewSprite(animation *Animation) *Sprite

func (*Sprite) Draw

func (sprite *Sprite) Draw(target *ebiten.Image)

func (*Sprite) SetAnimation added in v0.0.2

func (sprite *Sprite) SetAnimation(animation *Animation, repeat bool)

func (*Sprite) Start

func (sprite *Sprite) Start(at time.Time)

func (*Sprite) Stop

func (sprite *Sprite) Stop()

func (*Sprite) Update

func (sprite *Sprite) Update(at time.Time)

type Spritesheet added in v0.0.1

type Spritesheet interface {
	// Animation returns the tagged animation with the specified name.
	Animation(name string) (*Animation, error)

	// AllAnimations returns a mapping of all tagged animations and their names.
	AllAnimations() (map[string]*Animation, error)
}

Spritesheet loads named Animations from a sprite sheet.

type VerticalAlignment

type VerticalAlignment func(y float64, height float64) float64

Jump to

Keyboard shortcuts

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