sparrow

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2023 License: MIT Imports: 8 Imported by: 0

README

sparrow

Go Reference

sparrow is a Sparrow v2 texture atlas (PNG and XML pair, the same format that FNF uses) library for Go.

Handy if you're making a game that uses Sparrow v2 or rewriting FNF in Go (like me).

Features

  • Decoding
  • Encoding
  • Image / Frame extracting

Basic Usage

package main

import (
    "image/png"
    "github.com/MatusOllah/sparrow"
)

func main() {
    // Here you can use any png & atlas, I'm using the awesome BOYFRIEND.xml
    img, err := png.Decode("BOYFRIEND.png")
    if err != nil {
        panic(err)
    }

    atlas, err := sparrow.ParseTextureAtlas("BOYFRIEND.xml")
    if err != nil {
        panic(err)
    }

    // This gets / extracts the BF HEY!!0025 frame
    bfHey := atlas.MustGetSubTexture("BF HEY!!0025")
    bfHeyImg := bfHey.MustImage(img)

    // This returns all frames as a map
    frames := atlas.EnumerateSubTextures()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCroppingUnsupported error = errors.New("image does not support cropping")
View Source
var ErrSubTextureDoesNotExist error = errors.New("sub-texture does not exist")

Functions

This section is empty.

Types

type SubTexture

type SubTexture struct {
	Name        string `xml:"name,attr"`
	X           int    `xml:"x,attr"`
	Y           int    `xml:"y,attr"`
	Width       int    `xml:"width,attr"`
	Height      int    `xml:"height,attr"`
	FrameX      int    `xml:"frameX,attr"`
	FrameY      int    `xml:"frameY,attr"`
	FrameWidth  int    `xml:"frameWidth,attr"`
	FrameHeight int    `xml:"frameHeight,attr"`
}

func NewSubTexture

func NewSubTexture(name string, x, y, width, height int) *SubTexture

NewSubTexture returns a new SubTexture.

func NewSubTextureFromRect

func NewSubTextureFromRect(name string, r image.Rectangle) *SubTexture

NewSubTextureFromRect returns a new SubTexture from r.

func (*SubTexture) Image

func (st *SubTexture) Image(i image.Image) (image.Image, error)

Image returns an true, cropped image representing the portion of the image i visible through the st's rect.

func (*SubTexture) MustImage

func (st *SubTexture) MustImage(i image.Image) image.Image

MustImage simply calls Image and returns nil if an error occurs.

func (*SubTexture) Rect

func (st *SubTexture) Rect() image.Rectangle

Rect returns the st's uncropped rect.

type TextureAtlas

type TextureAtlas struct {
	ImagePath   string        `xml:"imagePath,attr"`
	SubTextures []*SubTexture `xml:"SubTexture"`
}

func NewTextureAtlas

func NewTextureAtlas() *TextureAtlas

NewTextureAtlas returns a new TextureAtlas.

func ParseTextureAtlas

func ParseTextureAtlas(xmlData []byte) (*TextureAtlas, error)

ParseTextureAtlas parses a Sparrow v2 texture atlas in XML format.

func ParseTextureAtlasFromFS added in v1.1.0

func ParseTextureAtlasFromFS(fsys fs.FS, path string) (*TextureAtlas, error)

ParseTextureAtlasFromFS parses a Sparrow v2 texture atlas in XML format from a filesystem.

func (*TextureAtlas) Encode

func (ta *TextureAtlas) Encode() ([]byte, error)

Encode encodes a TextureAtlas as XML.

func (*TextureAtlas) EnumerateSubTextures added in v1.1.0

func (ta *TextureAtlas) EnumerateSubTextures() map[string]*SubTexture

EnumerateSubTextures returns a map that contains all sub-textures.

func (*TextureAtlas) GetSubTexture added in v1.1.0

func (ta *TextureAtlas) GetSubTexture(name string) (*SubTexture, error)

GetSubTexture finds and returns a SubTexture with the specified name.

func (*TextureAtlas) MustGetSubTexture added in v1.1.0

func (ta *TextureAtlas) MustGetSubTexture(name string) *SubTexture

MustGetSubTexture simplay calls GetSubTexture and returns nil if an error occurs.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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