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) FromSprite ¶
fromSprite sets up current animation based on sprite name from collection.
func (*Anim) SetDirection ¶
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.
type Collection ¶
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 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.