sprite

package module
v0.0.0-...-94baa75 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2014 License: BSD-3-Clause Imports: 5 Imported by: 0

README

A fork of golang.org/x/mobile/sprite.
Used to prototype ideas.
Not terrible ideas will be backported to mobile/sprite.

Under the same license as the go.mobile subrepository.

Documentation

Overview

Package sprite provides a 2D scene graph for rendering and animation.

A tree of nodes is drawn by a rendering Engine, provided by another package. The OS-independent Go version based on the image package is:

code.google.com/p/go.mobile/sprite/portable

An Engine draws a screen starting at a root Node. The tree is walked depth-first, with affine transformations applied at each level.

Nodes are rendered relative to their parent.

Typical main loop:

for each frame {
	quantize time.Now() to a clock.Time
	process UI events
	modify the scene's nodes and animations (Arranger values)
	e.Render(scene, t)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Arranger

type Arranger interface {
	Arrange(e Engine, n *Node, t clock.Time)
}

type Curve

type Curve int32

type Engine

type Engine interface {
	// LoadTexture loads a texture into the active Engine.
	LoadTexture(a image.Image) (Texture, error)

	// LoadPath loads a vector path into the active Engine.
	//
	// The path slice is an encoded sequence of tagged bezier
	// curve control points. Control points are geom.Pt co-ordinates.
	//  The first control point of a curve is the final control point
	// of the previous curve.
	//
	// Valid tags:
	//	{0, x, y}           - start control point
	//	{1, x, y}           - line segment control point
	//	{2, x1, y1, x2, y2} - quadratic segment control points
	//
	// TODO(crawshaw): support cubic segments
	// TODO(crawshaw): make []float32?
	LoadCurve(path []geom.Pt) (Curve, error)

	UnloadCurve(c Curve)

	Render(scene *Node, t clock.Time)
}

type Node

type Node struct {
	Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

	// Transform is an affine transformation matrix for this
	// node and its children.
	Transform *f32.Affine

	Arranger Arranger
	SubTex   SubTex
	Curve    Curve
}

A Node is a renderable element and forms a tree of Nodes.

func (*Node) AppendChild

func (n *Node) AppendChild(c *Node)

AppendChild adds a node c as a child of n.

It will panic if c already has a parent or siblings.

func (*Node) RemoveChild

func (n *Node) RemoveChild(c *Node)

RemoveChild removes a node c that is a child of n. Afterwards, c will have no parent and no siblings.

It will panic if c's parent is not n.

type SubTex

type SubTex struct {
	T Texture
	R image.Rectangle
}

type Texture

type Texture interface {
	Bounds() (w, h int)
	Download(r image.Rectangle, dst draw.Image)
	Upload(r image.Rectangle, src image.Image)
	Unload()
}

Directories

Path Synopsis
Package clock provides a clock and time functions for a sprite engine.
Package clock provides a clock and time functions for a sprite engine.
Package glsprite blah blah blah TODO.
Package glsprite blah blah blah TODO.
Package portable implements a sprite Engine using the image package.
Package portable implements a sprite Engine using the image package.
Package raster is experimental vector drawing for the sprite package.
Package raster is experimental vector drawing for the sprite package.

Jump to

Keyboard shortcuts

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