Documentation ¶
Overview ¶
Package sprite is an Aseprite JSON loader written in Golang.
Index ¶
- Variables
- type Direction
- type File
- type Frame
- type Layer
- type Player
- func (p *Player) Clone() *Player
- func (p *Player) CurrentFrame() (Frame, bool)
- func (p *Player) CurrentFrameCoords() (int, int, int, int)
- func (p *Player) CurrentUVCoords() (float64, float64)
- func (p *Player) CurrentUVCoordsDelta() (float64, float64)
- func (p *Player) Draw(screen *ebiten.Image) error
- func (p *Player) FrameIndexInAnimation() int
- func (p *Player) Play(tagName string) error
- func (p *Player) SetFrameIndex(frameIndex int)
- func (p *Player) TouchingTagByName(tagName string) bool
- func (p *Player) TouchingTags() []*Tag
- func (p *Player) Update(dt float32)
- type Slice
- type SliceKey
- type Tag
Constants ¶
This section is empty.
Variables ¶
var (
ErrNoTagByName = errors.New("no tags by name")
)
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct { Path string // Path to the file (exampleSprite.json); blank if the *File was loaded using Read(). ImagePath string // Path to the image associated with the Aseprite file (exampleSprite.png). Width, Height int32 // Overall width and height of the File. FrameWidth, FrameHeight int32 // Width and height of the frames in the File. Frames []Frame // The animation Frames present in the File. Tags map[string]*Tag // A map of Tags, with their names being the keys. Layers []Layer // A slice of Layers. Slices []Slice // A slice of the Slices present in the file. }
File contains all properties of an exported aseprite file. ImagePath is the absolute path to the image as reported by the exported Aseprite JSON data. Path is the string used to open the File if it was opened with the Open() function; otherwise, it's blank.
func OpenAseprite ¶
OpenAseprite will use os.ReadFile() to open the Aseprite JSON file path specified to parse the data. Returns a *goaseprite.File. This can be your starting point. Files created with Open() will put the JSON filepath used in the Path field.
func ReadAseprite ¶
ReadAseprite returns a *goaseprite.File for a given sequence of bytes read from an Aseprite JSON file.
func ReadSpritesheet ¶
func (*File) CreatePlayer ¶
CreatePlayer returns a new animation player that plays animations from a given Aseprite file.
func (*File) CreatePlayerWithImage ¶
type Layer ¶
Layer contains details regarding the layers exported from Aseprite, including the layer's name (string), opacity (0-255), and blend mode (string).
type Player ¶
type Player struct { File *File PlaySpeed float32 // The playback speed; altering this can be used to globally slow down or speed up animation playback. CurrentTag *Tag // The currently playing animation. FrameIndex int // The current frame of the File's animation / tag playback. PrevFrameIndex int // The previous frame in the playback. // OnLoop gets called when the playing animation / tag does a complete loop. For a ping-pong // animation, this is a full forward + back cycle. OnLoop func(p *Player) // OnFrameChange gets called when the playing animation / tag changes frames. OnFrameChange func(p *Player, frame int) // OnTagEnter gets called when entering a tag from "outside" of it (i.e. if not playing a //tag and then it gets played, this gets called, or if you're playing a tag and you pass // through another tag). OnTagEnter func(p *Player, t *Tag) OnTagExit func(p *Player, t *Tag) // OnDraw callbacl called just before drawing the sprite, if return false the draw is aborted. OnDraw func(p *Player, screen, img *ebiten.Image, opts *ebiten.DrawImageOptions) bool // contains filtered or unexported fields }
Player is an animation player for Aseprite files.
func (*Player) CurrentFrame ¶
CurrentFrame returns the current frame for the currently playing Tag in the File and a boolean indicating if the Player is playing a Tag or not.
func (*Player) CurrentFrameCoords ¶
CurrentFrameCoords returns the four corners of the current frame, of format (x1, y1, x2, y2). If File.CurrentFrame() is nil, it will instead return all -1's.
func (*Player) CurrentUVCoords ¶
CurrentUVCoords returns the top-left corner of the current frame, of format (x, y). If File.CurrentFrame() is nil, it will instead return (-1, -1).
func (*Player) CurrentUVCoordsDelta ¶
CurrentUVCoordsDelta returns the current UV Coords as a coordinate movement delta. For example, if an animation were to return the X-axis UV coordinates of : [ 0, 0, 0, 0, 0.5, 0.5, 0.5, 0.5 ], CurrentUVCoordsDelta would return [ 0, 0, 0, 0, 0.5, 0, 0, 0 ], as the UV coordinate only changes on that one frame in the middle, from 0 to 0.5. Once it goes to the end, it would return -0.5 to return back to the starting frame.
func (*Player) FrameIndexInAnimation ¶
FrameIndexInAnimation returns the currently visible frame index, using the playing animation as the range. This means that a FrameIndexInAnimation of 0 would be the first frame in the currently playing animation, regardless of what frame in the sprite strip that is). If no animation is being played, this function will return -1.
func (*Player) Play ¶
Play sets the specified tag name up to be played back. A tagName of "" will play back the entire file.
func (*Player) SetFrameIndex ¶
SetFrameIndex sets the currently visible frame to frameIndex, using the playing animation as the range. This means calling SetFrameIndex with a frameIndex of 2 would set it to the third frame of the animation that is currently playing.
func (*Player) TouchingTagByName ¶
TouchingTagByName returns if a tag by the given name is being touched by the Player (tag).
func (*Player) TouchingTags ¶
TouchingTags returns the tags currently being touched by the Player (tag).
type Slice ¶
type Slice struct { Name string // Name is the name of the Slice, as specified in Aseprite. Data string // Data is blank by default, but can be specified on export from Aseprite to be whatever you need it to be. Keys []SliceKey // The individual keys (positions and sizes of Slices) according to the Frames they operate on. Color int64 }
Slice represents a Slice (rectangle) that was defined in Aseprite and exported in the JSON file.
type SliceKey ¶
SliceKey represents a Slice's size and position in the Aseprite file on a specific frame. An individual Aseprite File can have multiple Slices inside, which can also have multiple frames in which the Slice's position and size changes. The SliceKey's Frame indicates which frame the key is operating on.