Documentation ¶
Overview ¶
Package aseprite is the primary package to interface with the parsed aseprite files and its animations.
Index ¶
- type Animation
- type AnimationInfo
- type Boundary
- type Direction
- type Error
- type File
- func (f *File) Animation(animation string) *Animation
- func (f *File) FrameBoundaries() Boundary
- func (f *File) HasAnimation(animation string) bool
- func (f *File) HasSlice(slice string) bool
- func (f *File) Play(animation string) error
- func (f *File) Slice(slice string) *Slice
- func (f *File) Update(dt float32)
- type Frame
- type FrameData
- type Layer
- type MetaData
- type Slice
- type SliceKey
- type WidthHeight
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Animation ¶
type Animation struct { // Name of the animation. Name string `json:"name"` // The beginning frame of the animation. From int `json:"from"` // The ending frame of the animation. To int `json:"to"` // Animation's playback direction. // Example: // - PlayForward // - PlayReverse // - PlayPingPong Direction Direction `json:"direction"` }
Animation holds the metadata about the playing animation including its beginning frame (From) and ending frame (To).
type AnimationInfo ¶
type AnimationInfo struct { CurrentAnimation *Animation PlaySpeed float32 Playing bool PrevFrame int PrevCurrentFrame int // what? CurrentFrame int // contains filtered or unexported fields }
AnimationInfo stores essential information used when using the update game loop.
func (*AnimationInfo) AnimationFinished ¶
func (i *AnimationInfo) AnimationFinished() bool
AnimationFinished returns a boolean if the currently used animation being used for the Game Loop is finished playing.
func (*AnimationInfo) IsPlaying ¶
func (i *AnimationInfo) IsPlaying(animation string) bool
IsPlaying returns a boolean if the provided animation is currently being used for the Game Loop.
type Boundary ¶
type Boundary struct { X int `json:"x"` Y int `json:"y"` Width int `json:"w"` Height int `json:"h"` }
Boundary is a basic object to store position coordinates, width, and height.
type Direction ¶
type Direction uint8
Direction represents the playback directions for an animation.
const ( // PlayForward playsback frames in incremental order. // Frames [0, 1, 2, 3, 4, 5] // Order [0, 1, 2, 3, 4, 5] PlayForward Direction = iota // forward // PlayReverse playsback frames in decremental order. // Frames [0, 1, 2, 3, 4, 5] // Order [5, 4, 3, 2, 1, 0] PlayReverse // reverse // PlayPingPong plays frames in incremental order, then once reaching the // last frame the animation will play in decremental order. // Frames [0, 1, 2, 3, 4, 5] // Order [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0, ...] PlayPingPong // pingpong )
func DirectionFromString ¶
DirectionFromString returns a Direction based on the value of the string. Note: This function assumes that the string is lowercased correctly.
func (*Direction) UnmarshalJSON ¶
UnmarshalJSON unmarshals a byte slice representing the string values of the data and then sets the value to a Direction.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is used as a custom error for the aseprite package.
type File ¶
type File struct { Frames FrameData `json:"frames"` Meta MetaData `json:"meta"` AnimationInfo }
File is the final parsed aseprite file. This includes helpful methods to interact and get information about the animations and its frames.
func NewFile ¶
NewFile takes the file's data and unmarshals it into a new File. What's the point in using this? Maybe saving an extra import? I'm not really sure at this point.
func Open ¶ added in v0.3.0
Open will remove some of the pain of reading the data from the aseprite JSON file and loading it into memory then giving it over here to turn into a file. Instead this will open the filepath and then read the bytes and return an aseprite File.
func (*File) Animation ¶ added in v0.3.0
Animation will search the slices in the aseprite file and return any animation that matches the name provided. Note: Animation is a duplicate of GetSlice is almost every way. This is because of the limitations of Golang that I cannot address. There are no generics in the language yet that would allow me to prevent this code duplication.
func (*File) FrameBoundaries ¶ added in v0.3.0
FrameBoundaries will return the current frame's bounding box.
func (*File) HasAnimation ¶
HasAnimation returns a boolean value that represents whether the provided animation is contained in the aseprite file.
func (*File) HasSlice ¶
HasSlice returns a boolean value that represents whether the provided slice is contained in the aseprite file.
func (*File) Play ¶
Play will mark an animation in the list of animations listed in the aseprite file to be used for the Update method.
func (*File) Slice ¶ added in v0.3.0
Slice will search the slices in the aseprite file and return any slice that matches the name provided. Note: Slice is a duplicate of GetAnimation is almost every way. This is because of the limitations of Golang that I cannot address. There are no generics in the language yet that would allow me to prevent this code duplication.
type Frame ¶
type Frame struct { FileName string `json:"filename,omitempty"` FrameBoundaries Boundary `json:"frame"` Rotated bool `json:"rotated"` Trimmed bool `json:"trimmmed"` SpriteSourceSize Boundary `json:"spriteSourceSize"` SourceSize WidthHeight `json:"sourceSize"` Duration float32 `json:"duration"` }
Frame contains the data about a frame.
type FrameData ¶
type FrameData struct { IsMap bool `json:"-"` // contains filtered or unexported fields }
FrameData contains all the frames in the animation and their data.
func (*FrameData) FrameAtIndex ¶
FrameAtIndex uses the local copy of the sliced frames and searches for the frame on the nth index.
func (*FrameData) FrameAtKey ¶
FrameAtKey uses the local copy of the mapped frames and searches for the frame assigned to the given key.
func (*FrameData) FrameSlice ¶
FrameSlice returns a reference to the sliced version of the frames.
func (*FrameData) LenFrames ¶
LenFrames return the length of the number of frames in the aseprite file.
func (*FrameData) UnmarshalJSON ¶
UnmarshalJSON handles the problem of different layouts in the JSON file. Sometimes the file can be a map for the frames and sometimes it can be a slice.
type Layer ¶
type Layer struct { Name string `json:"name"` Opacity int `json:"opacity"` BlendMode string `json:"blendMode"` }
Layer contains the data about the individual animation layer including its name, opacity, and blending mode. Layers can be used to stack on top of each other to create unique affects on the animation itself.
type MetaData ¶
type MetaData struct { App string `json:"app"` Version string `json:"version"` Image string `json:"image"` Format string `json:"format"` Size WidthHeight `json:"size"` Scale string `json:"scale"` Animations []Animation `json:"frameTags,omitempty"` Layers []Layer `json:"layers,omitempty"` Slices []Slice `json:"slices,omitempty"` }
MetaData is the data about the overall animation including animation playback directions, layer opacity, and pivot points.
func (*MetaData) LenAnimations ¶
LenAnimations returns the length of the Animations slice.
type Slice ¶
type Slice struct { Name string `json:"name"` Color string `json:"color"` Keys []SliceKey `json:"keys"` }
Slice is used for slicing up an image in a layer or animation in aseprite. In this struct it contains the information about the slice itself including its keys, color, and the name of the slice.
type SliceKey ¶
type SliceKey struct { FrameNum int `json:"frame"` Bounds Boundary `json:"bounds"` Center Boundary `json:"center"` Pivot image.Point `json:"pivot"` }
SliceKey stores the information about each slice including its frame number, the boundaries of the slice, and more.
type WidthHeight ¶
WidthHeight is a basic object to store width and height.