animation

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2020 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorVersionNotSupported = "Version \"%s\" not supported"
	ErrorNoAnims             = "File must have at least one animation declared, none found"
)

Returned errors

View Source
const (
	SingleReverse = iota - 2
	CircularReverse
	Circular
	Single
)

Animation types of cycles

View Source
const (
	ErrorAnimationDoesNotExist = "Animation '%s' does not exist"
)

Returned errors

Variables

This section is empty.

Functions

This section is empty.

Types

type AnimFile

type AnimFile struct {
	Version string
	Sheet   string
	Anims   map[string]struct {
		Frames   int
		Cycle    string
		Duration float64
		YOffset  float64 `json:"y_offset"`
		Width    float64
		Height   float64
	}
}

AnimFile defines the structure of a disk file containing information about animations

type Animation

type Animation struct {
	Position pixel.Vec
	Dir      float64
	// contains filtered or unexported fields
}

Animation implements an animated sprite

func Deserialize

func Deserialize(r io.Reader, pos pixel.Vec) (*Animation, error)

func NewAnimation

func NewAnimation(pos pixel.Vec, numberAnims int) *Animation

NewAnimation returns a new Sprite instance to be drawn at position x, y

func (*Animation) AddAnim

func (a *Animation) AddAnim(idx string, pic pixel.Picture, yOffset, width, height float64, numberFrames int, duration float64, cycle string)

AddAnim adds a new animation to the Sprite, identified with ID, whose frames are taken from pic from left to right, starting from X = 0 duration defines how many seconds should it take for the animation to complete a cycle

func (*Animation) CurrentAnim

func (a *Animation) CurrentAnim() string

CurrentAnim returns the current animation index

func (*Animation) CurrentFrameNumber

func (a *Animation) CurrentFrameNumber() int

CurrentFrameNumber returns the frame number that it is drawn

func (*Animation) Draw

func (a *Animation) Draw(target pixel.Target, dt float64)

Draw draws Sprite current frame on target, and updates the former if needed

func (*Animation) IsOver added in v0.1.1

func (a *Animation) IsOver() bool

IsOver returns wheter an animation is over or not

func (*Animation) SetCurrentAnim

func (a *Animation) SetCurrentAnim(ID string) error

SetCurrentAnim defines which animation to play

Jump to

Keyboard shortcuts

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