gosang

package module
v0.0.0-...-47855bf Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2019 License: MIT Imports: 7 Imported by: 0

README

gosang

godoc goreportcard

Gersang sprite library for Go

Example

Here's a simple example that uses gosang to extract frame images from sprite to files in PNG format.

It works well for both 8-bit sprite(.spr) and 32-bit(.S32) sprite.

package main

import (
	"fmt"
	"image/png"
	"os"

	"github.com/hallazzang/gosang"
)

func main() {
	f, err := os.Open(`data\BUTTMENU_ONLINE_1.S32`)
	if err != nil {
		panic(err)
	}
	defer f.Close()
	sp, err := gosang.OpenSprite(f)
	if err != nil {
		panic(err)
	}
	for i := 0; i < sp.FrameCount(); i++ {
		frame, err := sp.Frame(i)
		if err != nil {
			panic(err)
		}
		func() {
			out, err := os.Create(fmt.Sprintf("output%d.png", i))
			if err != nil {
				panic(err)
			}
			defer out.Close()
			if err := png.Encode(out, frame.Image()); err != nil {
				panic(err)
			}
		}()
	}
}

Documentation

Overview

Package gosang provides useful interfaces and functions for reading and writing Gersang sprites.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Frame

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

Frame represents single frame in sprite.

func (*Frame) Height

func (fr *Frame) Height() int

Height returns frame's height, in pixels.

func (*Frame) Image

func (fr *Frame) Image() image.Image

Image returns frame's image.

func (*Frame) Index

func (fr *Frame) Index() int

Index returns frame's index in sprite.

func (*Frame) Width

func (fr *Frame) Width() int

Width returns frame's width, in pixels.

type Sprite

type Sprite interface {
	ColorBits() int   // Color bits. 8 or 32.
	HasAlpha() bool   // Whether frame has alpha channel or not.
	FrameWidth() int  // Frame's width in pixels.
	FrameHeight() int // Frame's height in pixels.
	FrameCount() int
	Width() int
	Height() int
	Frame(idx int) (*Frame, error) // Specific frame's data.
	Save(w io.Writer) error        // Write sprite data to w.
	// contains filtered or unexported methods
}

Sprite represents single sprite. It can either be 8-bit or 32-bit sprite.

func OpenSprite

func OpenSprite(r io.ReaderAt) (Sprite, error)

OpenSprite creates new sprite from r. It can accept all three type of sprites: 8-bit sprite(.spr), 32-bit sprite w/o alpha channel, 32-bit sprite w/ alpha channel.

Jump to

Keyboard shortcuts

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