Documentation ¶
Index ¶
- Variables
- func SetTPS()
- type AniFrame
- type Animation
- func (a *Animation) Bounds() image.Rectangle
- func (a *Animation) Clone() Animation
- func (a *Animation) DrawPackedTo(screen *ebiten.Image, optFunc func(options *ebiten.DrawImageOptions))
- func (a *Animation) DrawTo(screen *ebiten.Image, options *ebiten.DrawImageOptions)
- func (a *Animation) Frame() AniFrame
- func (a *Animation) FrameIdx() int
- func (a *Animation) OnEnd(tag string, callback Callback)
- func (a *Animation) Pause()
- func (a *Animation) Restart()
- func (a *Animation) Resume()
- func (a *Animation) SetFrame(idx int) error
- func (a *Animation) SetTag(tag string)
- func (a *Animation) Toggle()
- func (a *Animation) Update()
- type Callback
- type Frame
- type FrameTag
- type Layer
- type Meta
- type Rect
- type Size
- type Slice
- type SliceKey
- type SpriteSheet
- type SubImager
Constants ¶
This section is empty.
Variables ¶
var TPS int
Functions ¶
Types ¶
type AniFrame ¶
type AniFrame struct { // FrameIdx is the original index of this frame from Aseprite. FrameIdx int // Image represents an image to use. For efficiency, it's recommended to use subimage for each frame. Image image.Image // DurationMillis represents the number of milliseconds this frame should be shown. DurationMillis int64 // SourceRect is the source rectangle in the sprite sheet. Primarily used for packed sprites. SourceRect image.Rectangle }
AniFrame denotes a single frame of this animation.
type Animation ¶
type Animation struct { // FramesByTagName lists all frames, keyed by their tag. Take care when editing the images associated with this map, // as Asebiten uses subimages for each tag, even when that's redundant. FramesByTagName map[string][]AniFrame // Source is a struct representing the raw JSON read from the Aesprite SpriteSheet on import. Cast to the correct // version's SpriteSheet model to use. Source SpriteSheet // contains filtered or unexported fields }
Animation is a collection of animations, keyed by a name called a 'tag'. Each tagged animation starts from its first frame and runs until its last frame before looping back to the beginning. Use Callback to take action at the end of a frame. Animation is not thread-safe, but all Callbacks are run synchronously.
Every Animation has an empty tag which loops through every frame in the Sprite Sheet in order. This is the default animation which will be played.
func LoadAnimation ¶
LoadAnimation loads a sprite from the provided filesystem, based on the provided json path. The image paths are assumed to be found in the directory relative to the path passed in. All images in the animation are loaded onto the CPU
func LoadCPUAnimation ¶ added in v0.5.2
LoadCPUAnimation loads an animation which is drawn from the CPU each frame. This is good for larger animations such as cinematics done in Aseprite.
func NewAnimation ¶
NewAnimation creates a new Animation using the provided map from tag names to a list of frames to run. If a nil map is passed in this func also returns nil.
func NewFlyweightAnimation ¶
NewFlyweightAnimation creates a new animation which uses the SpriteSheet already loaded up in the provided animation.
func (*Animation) Clone ¶
Clone creates a shallow clone of this animation which uses the same SpriteSheet as the original, but gets its own callbacks and state. The tag, frame, and callbacks set on the source animation are copied for convenience. All timing information is reset at the time the Animation is cloned.
func (*Animation) DrawPackedTo ¶
func (a *Animation) DrawPackedTo(screen *ebiten.Image, optFunc func(options *ebiten.DrawImageOptions))
DrawPackedTo draws a packed animation to the proveded screen. A func to manage any draw options is provided -- the translations needed to unpack frames from packed sprite sheets have already been performed.
func (*Animation) DrawTo ¶
func (a *Animation) DrawTo(screen *ebiten.Image, options *ebiten.DrawImageOptions)
DrawTo draws an animation from to the provided screen using the provided options. Does not automatically perform translation for packed sprite sheets, since doing so requires modifying GeoM prior to other transformations. See DrawPackedTo for that functionality.
func (*Animation) OnEnd ¶
OnEnd registers the provided Callback to run on the same frame that the final frame of the animation is crossed. Each Callback is called only once every time the animation ends, even if the animation ends multiple times during a single frame. Callbacks for a given tag can be disabled by calling OnEnd(tag, nil).
Note: for "reverse" or "pingpong" animations, the end of the animation is defined as the end of the sequence of frames stored by asebiten.
func (*Animation) Pause ¶
func (a *Animation) Pause()
Pause pauses a currently running animation. Animations are running by default.
func (*Animation) Restart ¶
func (a *Animation) Restart()
Restart restarts the currently running animation from the beginning.
func (*Animation) Resume ¶
func (a *Animation) Resume()
Resume resumes a previously paused animation. Animations are running by default.
func (*Animation) SetTag ¶
SetTag sets the currently running tag to the provided tag name. If the tag name is different from the currently running tag, this func also sets the frame number to 0.
type Callback ¶
type Callback func(*Animation)
Callback is used for animation callbacks, which are triggered whenever an animation runs out of frames. All callbacks are run synchronously on the same thread where Animation.Update() is called.
type SpriteSheet ¶
type SpriteSheet struct { Frames []*Frame `json:"frames"` Meta Meta `json:"meta"` // Image is the image referred to by the SpriteSheet. Image image.Image // Animations stores anmiations ready to go; keyed by frameTag. If no frametags are used the // entire sprite sheet is available under a single animation keyed by the empty string. Animations map[string]Animation }
SpriteSheet represents the json export format for an Aesprite sprite sheet, which has been exported with frames in an *Array*.
func LoadSpriteSheet ¶
func LoadSpriteSheet(fs fs.FS, jsonPath string) (SpriteSheet, error)
LoadSpriteSheet only loads sprite sheet metadata for use in whatever manner the caller would prefer. If you want an asebiten.Animation, you should probably use LoadAnimation instead.