sprite

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package sprite implements sprite collection loading from config file. Sprite can contain several frames and animation properties.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Anim

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

Anim controls sprite animation. Call Progress providing time in seconds passed since last frame. Call Current to obtain sprite name and current frame number.

func NewAnim

func NewAnim(col *Collection, name string, reverse bool) *Anim

NewAnim creates new animation.

func (*Anim) Current

func (a *Anim) Current() (name string, frame int)

Current returns current sprite name and frame.

func (*Anim) FromSprite

func (a *Anim) FromSprite(name string) bool

fromSprite sets up current animation based on sprite name from collection.

func (*Anim) Progress

func (a *Anim) Progress(dt float64)

Progress advances animation by given time in seconds.

func (*Anim) SetDirection

func (a *Anim) SetDirection(reverse, reset bool)

SetDirection sets animation direction. If reverse is true, animation will play from end to start frames. If reset is true, animation will start from the beginning.

func (*Anim) SetLoop

func (a *Anim) SetLoop(loop bool)

type Collection

type Collection struct {
	Sprites map[string]*Sprite
	Config  Config
}

Collection contains information about all sprites & animation properties, as well as a map to lookup sprites by their names.

func NewCollectionFromFile

func NewCollectionFromFile(fileName string) (*Collection, error)

NewCollectionFromFile creates sprite collection from yaml configuration file.

type Config

type Config struct {
	Files []*File `yaml:"files,omitempty"`
}

Config is the structure to store unmarshalled config.

type DrawOpts

type DrawOpts struct {
	Name   string
	Frame  int
	X      float64
	Y      float64
	ScaleX float64
	ScaleY float64
	// Rotation angle in radians.
	Rotation float64
	Color    color.Color
}

DrawOpts contains options for drawing sprite. Name is mandatory. Other fields can be left empty.

type File

type File struct {
	Name    string
	Sprites map[string]*Sprite `yaml:"sprites,omitempty"`
}

File represents one sprite sheet file.

type Sprite

type Sprite struct {
	Name       string `yaml:"-"`
	XOffset    int    `yaml:"xOffset,omitempty"`
	YOffset    int    `yaml:"yOffset,omitempty"`
	XOrigin    int    `yaml:"xOrigin,omitempty"`
	YOrigin    int    `yaml:"yOrigin,omitempty"`
	Width      int    `yaml:"width,omitempty"`
	Height     int    `yaml:"height,omitempty"`
	FrameCount int    `yaml:"frameCount,omitempty"`
	AnimLoop   bool   `yaml:"animLoop,omitempty"`
	AnimNext   string `yaml:"animNext,omitempty"`
	FrameMS    int    `yaml:"frameMS,omitempty"`
}

Sprite contains information about position and size of sprite in the sheet, it's origin point and animation properties. Sprite can contain several frames.

Jump to

Keyboard shortcuts

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