package sprite
import "git.teletypegames.org/engines/inkwell/sprite"
Package sprite holds the picture types characters and items are drawn with.
A Sprite is a picture or a sequence of them: a sheet and the frames cut from it, in order, at FrameTime seconds each, looping or holding the last. No frames means the whole sheet is the one frame, so a still item and a walking character are the same type.
A character has one Sprite per Pose the art covers, and the engine picks the pose: PoseWalk while it moves, PoseTalk while its line is up, PoseWait once it has stood still for WaitAfter seconds, PoseIdle otherwise — or the one SetPose holds until the character next walks or speaks. A pose the art does not cover falls back to PoseIdle.
Direction is not a second sheet. A Sprite says which way its artwork Facing looks, the character remembers the way it last moved, and the frame is mirrored when the two differ, so one walk cycle serves both directions.
Index
Constants
const WaitAfter = 8.0
WaitAfter is how long a character stands still before Wait replaces Idle.
Types
type Facing
type Facing int
Facing is left or right; the sheet is drawn as it is when the character faces the way the sheet does, and mirrored otherwise.
const ( // FacingRight is artwork that looks to the right; the zero value. FacingRight Facing = iota // FacingLeft is artwork that looks to the left. FacingLeft )
type Pose
type Pose int
Pose is what a character is doing, as far as its sprite is concerned. The engine picks it: Walk while moving, Talk while its line is up, Wait after standing still a while, Idle otherwise — or whatever SetPose held. A pose a character has no Sprite for falls back to Idle, and a character with no Idle is drawn as the placeholder figure.
const ( // PoseIdle is standing still; the fallback for every other pose. PoseIdle Pose = iota // PoseWalk is moving along a path. PoseWalk // PoseTalk is speaking a line. PoseTalk // PoseWait is standing still for longer than [WaitAfter]. PoseWait )
type Sprite
type Sprite struct { Sheet *inkbase.Asset // Frames are rectangles on the sheet, in playing order. Empty means one // frame, the sheet itself. Frames []inkbase.Rectangle // FrameTime is how long one frame shows, in seconds. 0 with several // frames shows the first and never advances. FrameTime float64 // Loop starts over after the last frame; off, the last frame holds. Loop bool // Faces is the way the artwork looks. A character walking the other way // is drawn mirrored, so one sheet serves both directions. Faces Facing }
Sprite is a picture or a sequence of them: a sheet, and the frames cut from it. No Frames means the whole sheet is the one frame, so a still item and a walking character are the same type — one has one frame, the other has eight and a FrameTime.
func (*Sprite) FrameAt
func (s *Sprite) FrameAt(elapsed float64) int
FrameAt is the frame showing after elapsed seconds from the start.
func (*Sprite) FrameCount
func (s *Sprite) FrameCount() int
FrameCount is the number of frames in the sprite: len(Frames), 1 when Frames is empty, and 0 for a nil Sprite.
func (*Sprite) FrameRect
func (s *Sprite) FrameRect(img *ebiten.Image, frame int) image.Rectangle
FrameRect is the rectangle of img that frame cuts out, clipped to img's bounds. With no Frames, or a frame index out of range, it is the whole of img.