anim

package module
v0.0.0-...-8bc22d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2023 License: MIT Imports: 4 Imported by: 0

README

ebiten-anim

Create a SpriteSheet to easily select parts of an image and create animations from them.

Usage

📖 Docs
Look at the example to see how to use the library.

// Create a spritesheet
SpriteSheet = anim.NewSpriteSheet(sprites, 8, 10, anim.SpriteSheetOptions{
    Scale: 16,
})

// Create an animation
frames := make([]anim.Frame, 5)
for x := 0; x <= 4; x++ {
    frames[x] = anim.NewFrame(SpriteSheet.GetSprite(x, 0), time.Second / 20)
}
Animation := anim.NewAnimation(frames)

// Update the animation
Animation.Update()

// Pause/play the animation
Animation.Pause()
Animation.Play()

// Draw the animation
Animation.Draw(screen, &ebiten.DrawImageOptions{})

// You can also just draw frames from the spritesheet without using animations
// This might be useful to avoid cluttering your Draw function with Image.SubImage
screen.DrawImage(SpriteSheet.GetSprite(0, 0), &ebiten.DrawImageOptions{})

Documentation

Overview

Package anim provides a simple way to create animations for use with ebiten

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {
	Frames        []Frame
	CurrentFrame  int
	LastFrameTime time.Time
	Paused        bool
}

Animation stores a list of Frames and other data regarding timing

func NewAnimation

func NewAnimation(frames []Frame) *Animation

NewAnimation returns a new Animation

func (*Animation) Draw

func (a *Animation) Draw(surface *ebiten.Image, op *ebiten.DrawImageOptions)

Draw draws the animation to the surface with the provided DrawImageOptions

func (*Animation) Pause

func (a *Animation) Pause()

Pause pauses the animation

func (*Animation) Play

func (a *Animation) Play()

Play resumes the animation

func (*Animation) Update

func (a *Animation) Update()

Update updates

type Frame

type Frame struct {
	Image    *ebiten.Image
	Duration time.Duration // how long to draw this frame for
}

Frame stores a single frame of an Animation. It contains an image and how long it should be drawn for

func NewFrame

func NewFrame(image *ebiten.Image, duration time.Duration) Frame

NewFrame returns a new Frame

type SpriteSheet

type SpriteSheet struct {
	Image       *ebiten.Image // original image which was passed on creation
	PaddedImage *ebiten.Image
	Sprites     []*ebiten.Image

	SpriteWidth  int // how big each sprite is
	SpriteHeight int
	SpritesWide  int // how many sprites are in the sheet
	SpritesHigh  int

	Scale            int
	OutlineThickness int
	OutlineColor     color.RGBA
}

SpriteSheet stores the image and information about the sizing of the SpriteSheet

func NewSpriteSheet

func NewSpriteSheet(img *ebiten.Image, origSpriteWidth, origSpriteHeight int, options SpriteSheetOptions) *SpriteSheet

NewSpriteSheet returns a new SpriteSheet

func (*SpriteSheet) GetSprite

func (s *SpriteSheet) GetSprite(x, y int) *ebiten.Image

GetSprite returns the sprite at the position x,y in the tilesheet

type SpriteSheetOptions

type SpriteSheetOptions struct {
	Scale            int
	OutlineThickness int
	OutlineColor     color.RGBA
}

SpriteSheetOptions are the options which are passed to the NewSpriteSheet function

Directories

Path Synopsis
examples
scaleAndOutline
Package main 👍
Package main 👍
spinningMelon
Package main 👍
Package main 👍
tiles
Package main 👍
Package main 👍

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL