Documentation
¶
Index ¶
- Constants
- func MakePingPong(frames []*ebiten.Image) []*ebiten.Image
- func SubImages(spriteSheet *ebiten.Image, x, y, w, h, subImageCount int, vertical bool) []*ebiten.Image
- type Animation
- type AnimationPlayer
- func (ap *AnimationPlayer) Anim() string
- func (ap *AnimationPlayer) Atlas() string
- func (ap *AnimationPlayer) CurrentAnimFPS() float64
- func (ap *AnimationPlayer) NewAnim(stateName string, x, y, w, h, frameCount int, pingPong bool, vertical bool, ...)
- func (ap *AnimationPlayer) PauseAtFrame(index int)
- func (ap *AnimationPlayer) SetAllFPS(FPS float64)
- func (ap *AnimationPlayer) SetAnim(animName string)
- func (ap *AnimationPlayer) SetAnimFPS(animName string, FPS float64)
- func (ap *AnimationPlayer) SetAtlas(atlasName string)
- func (ap *AnimationPlayer) String() string
- func (ap *AnimationPlayer) Update()
- type Atlas
- type PlaybackData
Constants ¶
const Str string = `
Playback state;
Current Atlas: %v
Current Anim: %v
Paused: %v
Tick: %v
Current Anim Index %v
Current Anim FPS: %v
`
Variables ¶
This section is empty.
Functions ¶
func MakePingPong ¶ added in v1.0.2
func MakePingPong(frames []*ebiten.Image) []*ebiten.Image
MakePingPong arranges the animation indexes to play back and forth. [0 1 2 3] -> [0 1 2 3 2 1]
Types ¶
type Animation ¶
type Animation struct { Name string // Name of the aimation state Frames []*ebiten.Image // Animation frames FPS float64 // Animation playback speed (Frames Per Second). }
Animation for AnimationPlayer
type AnimationPlayer ¶
type AnimationPlayer struct { Data PlaybackData // Current frame of the current animation. // // The frame is dynamically updated with `AnimationPlayer.Update()`. CurrentFrame *ebiten.Image Atlases []Atlas // Animations and alternative sprite sheet atlases Animations map[string]map[string]*Animation }
AnimationPlayer plays and manages animations.
func NewAnimationPlayer ¶
func NewAnimationPlayer(atlases ...Atlas) *AnimationPlayer
NewAnimationPlayer returns new AnimationPlayer with spriteSheet
func (*AnimationPlayer) Anim ¶ added in v1.3.0
func (ap *AnimationPlayer) Anim() string
Anim returns current animation state name
func (*AnimationPlayer) Atlas ¶ added in v1.3.0
func (ap *AnimationPlayer) Atlas() string
Atlas returns current Atlas
func (*AnimationPlayer) CurrentAnimFPS ¶ added in v1.2.0
func (ap *AnimationPlayer) CurrentAnimFPS() float64
CurrentAnimFPS returns FPS of the current animation
func (*AnimationPlayer) NewAnim ¶ added in v1.2.0
func (ap *AnimationPlayer) NewAnim( stateName string, x, y, w, h, frameCount int, pingPong bool, vertical bool, FPS float64, )
NewAnim appends a new Animation to the AnimationPlayer and returns the Animation.
Parameters:
- x, y - Top-left coordinates of the first frame's rectangle.
- w, h - Width and height of the first frame's rectangle.
- frameCount - Animation frame count
- vertical - If true, frames are appended vertically, otherwise horizontally.
- pingPong - If true, arranges the animation indexes to play back and forth. [0 1 2 3 2 1]
- FPS - Playback FPS
func (*AnimationPlayer) PauseAtFrame ¶
func (ap *AnimationPlayer) PauseAtFrame(index int)
PauseAtFrame pauses the current animation at the frame. If index is out of range it does nothing.
func (*AnimationPlayer) SetAllFPS ¶
func (ap *AnimationPlayer) SetAllFPS(FPS float64)
SetAllFPS overwrites the FPS of all animations.
func (*AnimationPlayer) SetAnim ¶ added in v1.2.0
func (ap *AnimationPlayer) SetAnim(animName string)
SetAnim sets the animation and resets to the first frame.
If you assign ap.Data.CurrentAnim = "animName" directly, the animation will not be reset.
func (*AnimationPlayer) SetAnimFPS ¶ added in v1.2.0
func (ap *AnimationPlayer) SetAnimFPS(animName string, FPS float64)
SetAnimFPS sets FPS of the animation state.
func (*AnimationPlayer) SetAtlas ¶ added in v1.3.0
func (ap *AnimationPlayer) SetAtlas(atlasName string)
func (*AnimationPlayer) String ¶ added in v1.2.0
func (ap *AnimationPlayer) String() string
func (*AnimationPlayer) Update ¶
func (ap *AnimationPlayer) Update()
Update updates AnimationPlayer. Place this func inside Ebitengine `Game.Update()`.
// example func (g *Game) Update() error { animPlayer.Update() ...
type Atlas ¶ added in v1.1.0
type Atlas struct { Name string Image *ebiten.Image }
Atlas is a sprite sheet state for animation player.
It is used to easily switch between different sprite sheet variations that share the same coordinates.
type PlaybackData ¶ added in v1.2.0
type PlaybackData struct { // Current sprite sheet atlas CurrentAtlas string // CurrentAnim name (animation name) CurrentAnim string // If true, animations will be paused. Paused bool // Animation tick Tick float64 // Current animation frame index CurrentIndex int }
PlaybackData is AnimationPlayer's playback data. With this structure, the playback state can be saved to disk and reloaded.