spriteplus

package module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: GPL-3.0 Imports: 4 Imported by: 0

README

spriteplus

spriteplus is a golang library meant to be used along side the great Pixel library. It provides a generic SpriteSheet interface, and a few implementations.


Installation

go get github.com/cebarks/spriteplus


Usage

import "github.com/cebarks/spriteplus"
Sprite Sheets
//Create your sheet
sheet := spriteplus.NewSpriteSheet(false)

//Add your sprites to the sheet
err := sheet.AddSprite(gopherSprite, "gopher")
if err != nil {
  ...
}

//Optimize the texture
sheet.Optimize()


//These can be directly drawn to a Window (or any pixel.Target)
sprite := sheet.GetSprite("gopher") 
sprite.Draw(win, pixel.IM)

// or you can efficiently draw them using a batch with sheet.SourcePic()
pic := sheet.SourcePic()
batch := pixel.NewBatch(&pixel.TrianglesData{}, pic)

sprite.Draw(batch, pixel.IM)


batch.Draw(win, pixel.IM)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.


License

GNU GPLv3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Subimage added in v0.3.2

func Subimage(img image.Image, minX, minY, maxX, maxY int) (image.Image, error)

Subimage returns a subimage of the given image.Image

func SubimageRect added in v0.3.2

func SubimageRect(img image.Image, rect image.Rectangle) (image.Image, error)

SubimageRect returns a subimage of the given image.Image

Types

type Animation added in v0.2.0

type Animation struct {
	// contains filtered or unexported fields
}

Animation is a series of sprites that change after a certain number of frames in sequential order

func MakeAnimation added in v0.4.0

func MakeAnimation(sprites []*pixel.Sprite, frameLength int) (*Animation, error)

MakeAnimation builds an animation from the given sprite sprites and frame lengths.

func MakeAnimationFromSheet added in v0.4.0

func MakeAnimationFromSheet(ss SpriteSheet, ids []string, frameLength int) (*Animation, error)

MakeAnimationFromSheet builds an animation using sprites pulled from the given spritesheet using the given ids and frame lengths.

func (*Animation) Draw added in v0.2.0

func (ba *Animation) Draw(target pixel.Target, mat pixel.Matrix)

Draw draws the current sprite to the given target and updates

func (*Animation) Next added in v0.4.0

func (ba *Animation) Next()

Next force updates the animation to the next frame.

type SpriteSheet

type SpriteSheet struct {
	Cache map[string]*pixel.Sprite
	Alias map[string]int
	Packr *packer.Packer
}

SpriteSheet

func NewSpriteSheet added in v0.2.0

func NewSpriteSheet(debugDraw bool) *SpriteSheet

NewSpriteSheet creates a new instatiated sprite sheet

func (*SpriteSheet) AddSprite added in v0.2.0

func (ss *SpriteSheet) AddSprite(pic pixel.Picture, id string) error

func (*SpriteSheet) GetSprite

func (ss *SpriteSheet) GetSprite(id string) *pixel.Sprite

GetSprite will return the sprite in the Cache (or create&add it to the Cache) from the given int id

func (*SpriteSheet) Optimize added in v0.5.0

func (ss *SpriteSheet) Optimize()

Optimize the underlying texture

func (SpriteSheet) SourcePic

func (ss SpriteSheet) SourcePic() pixel.Picture

SourcePic returns the underlying pixel.Picture of the spritesheet (for sure with Batch rendering)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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