mobile: Index | Files | Directories

package sprite

import ""

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:

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, sz)


Package Files


type Arranger Uses

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

type Engine Uses

type Engine interface {
    Register(n *Node)
    Unregister(n *Node)

    LoadTexture(a image.Image) (Texture, error)

    SetSubTex(n *Node, x SubTex)
    SetTransform(n *Node, m f32.Affine) // sets transform relative to parent.

    // Render renders the scene arranged at the given time, for the given
    // window configuration (dimensions and resolution).
    Render(scene *Node, t clock.Time, sz size.Event)


type Node Uses

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

    Arranger Arranger

    // EngineFields contains fields that should only be accessed by Engine
    // implementations. It is exported because such implementations can be
    // in other packages.
    EngineFields struct {
        // TODO: separate TexDirty and TransformDirty bits?
        Dirty  bool
        Index  int32
        SubTex SubTex

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

func (*Node) AppendChild Uses

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 Uses

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 Uses

type SubTex struct {
    T   Texture
    R   image.Rectangle

type Texture Uses

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


clockPackage clock provides a clock and time functions for a sprite engine.
glspritePackage glsprite implements a sprite Engine using OpenGL ES 2.
portablePackage portable implements a sprite Engine using the image package.

Package sprite imports 5 packages (graph) and is imported by 35 packages. Updated 2020-12-22. Refresh now. Tools for package owners.