// Append simply adds an image from the aggregate to the end of our animation func (f *FrameAnimation) Append(imageLoc string) { img, err := Image.NewImage(imageLoc) if err != nil { Logging.Debug("Cannot create image: " + err.Error()) } f.animationImages = append(f.animationImages, &img) }
// SetImage puts a designated image from the agregate into our image which will be rendered func (s *SpriteRenderer) SetImage(imageLoc string) { img, err := Image.NewImage(imageLoc) if err != nil { Logging.Debug("Cannot create image: " + err.Error()) } s.img = &img }
// SetSubImage sets a designated part of an image for this sprite renderer // @param {[string]} this *SpriteRenderer [the base image path] // @param {[image.Rectangle]} this *SpriteRenderer [the rectangular bounds of designated part of image] // @return func (s *SpriteRenderer) SetSubImage(imageLoc string, bounds image.Rectangle) { img, err := Image.NewImage(imageLoc) if err != nil { Logging.Debug("Cannot create image: " + err.Error()) } img, err = img.SubImage(bounds) if err != nil { Logging.Debug("Cannot create sub image: " + err.Error()) } s.img = &img }
// SpliceSpriteSheetAnimation manually cuts up a row of a sprite sheet based on user defined dimensions and sets it as the current animation func SpliceSpriteSheetAnimation(imageLoc string, frameWidth, frameHeight, noOfFrames, rowNum int) *FrameAnimation { fa := newFrameAnimation() img, err := Image.NewImage(imageLoc) if err != nil { Logging.Debug("Cannot create image: " + err.Error()) } // throw warnings for bad input numOfRows := float32(img.Bounds().Dy() / frameHeight) numOfColumns := float32(img.Bounds().Dx() / frameWidth) if float32(noOfFrames) > numOfColumns || numOfColumns < 1 { Logging.Debug("WARNING: frames out of bounds") } if float32(rowNum) > numOfRows || numOfRows < 1 { Logging.Debug("WARNING: row desired out of bounds") } for j := 0; j < img.Bounds().Dy(); j += frameHeight { // only use our desired row (if specified) if rowNum != 0 && j/frameHeight != rowNum-1 { continue } // splice the row by the amount of intended images for i := 0; i < img.Bounds().Dx(); i += frameWidth { // only grab our desired number of frames (if specified) if noOfFrames != 0 && i/frameWidth >= noOfFrames { continue } // splice image from row, and insert piece into array b := image.Rect(i, j, i+frameWidth, j+frameHeight) spriteSheetPart, err := img.SubImage(b) if err != nil { Logging.Debug("Cannot create sub image: " + err.Error()) } fa.animationImages = append(fa.animationImages, &spriteSheetPart) } } return fa }