sprite

package
v0.0.0-...-b7bdad3 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2017 License: MIT Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Desc

type Desc struct {
	Name   string
	Frames []FrameDesc
}

Desc holds information that is shared between all instances of the same sprite.

func Psd

func Psd(data []byte) ([]Desc, error)

Psd takes data in psd format and extracts Descs from it.

Layers are parsed with the following format.

Sprite <Name>
  Frame <#> <duration>
    Rect <name>
    Point <name>
    Img
      <If Img is a folder then the layers it contains are joined, their names don't matter>

type FrameDesc

type FrameDesc struct {
	Img *ebiten.Image
	// Points maps a name to a list of positions relative to the sprite's top left corner
	Points map[string][]geo.Vec
	// Rects maps a name to a list of rectangles relative to the sprite's top left corner
	Rects    map[string][]geo.Rect
	Duration time.Duration
}

FrameDesc describes a single frame of a sprite

type Sprite

type Sprite struct {
	*Desc
	Loop bool
	// contains filtered or unexported fields
}

Sprite is an instance of a sprite described by Desc. This allows one to create many copies of the same sprite, each animating independently, but all of the common data is shared.

func (*Sprite) Draw

func (s *Sprite) Draw(dst *ebiten.Image, opts *ebiten.DrawImageOptions)

Draw the current frame to dst with the given options.

func (*Sprite) Ended

func (s *Sprite) Ended() bool

Ended returns true when the sprite is not looping and is done with the last frame.

func (*Sprite) Img

func (s *Sprite) Img() *ebiten.Image

Img returns the image for the current frame.

func (*Sprite) Points

func (s *Sprite) Points(name string) []geo.Vec

Points returns the points associated with the given name for the current frame.

func (*Sprite) Rects

func (s *Sprite) Rects(name string) []geo.Rect

Rects returns the rectangles associated with the given name for the current frame.

func (*Sprite) Start

func (s *Sprite) Start()

Start the sprite from the first frame.

func (*Sprite) Update

func (s *Sprite) Update(dt time.Duration)

Update subtracts dt from the time remaining on the current frame then advances the frame when it reaches 0. If Loop is true then the animation will start back from the beginning after reaching the end.

Jump to

Keyboard shortcuts

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