Circle Image

Pixaflux

Sprite It - Sprite

A sprite is a quad that is rendered in the image area. It has the following properties:

All these properties define the position, texture and colors of the sprite.

Sample Shape Script

This Shape Script add one sprite to the Sprite Context, and it's attributes control the shape of the sprite. Load this script in PixaFlux to explore how the sprite shapes are defined.

-- Load required Sprite Script libraries

vector2 = require("vector2")
matrix2 = require("matrix2")
box2 = require("box2")
rgbo = require("rgbo")
spriteIt = require("spriteIt")

-- Define the attributes

spriteIt.choiceAttribute("shape", spriteIt.shapes())
spriteIt.numberAttribute("index", 1.0, 1.0, 1000.0, 1.0, 0)
spriteIt.numberAttribute("parameter1", 0.0, -5.0, 5.0, 0.01, 3)
spriteIt.numberAttribute("parameter2", 0.0, -5.0, 5.0, 0.01, 3)
spriteIt.numberAttribute("parameter3", 0.0, -5.0, 5.0, 0.01, 3)
spriteIt.numberAttribute("parameter4", 0.0, -5.0, 5.0, 0.01, 3)
spriteIt.numberAttribute("mask1", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("mask2", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("mask3", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("mask4", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("modifier1", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("modifier2", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("modifier3", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("modifier4", 0.0, -1.0, 1.0, 0.01, 3)
spriteIt.numberAttribute("value", 0.0, -1.0, 1.0, 0.01, 3)

-- Resolve the attributes

spriteIt.resolveAttributeValues()

spriteContext = spriteIt.newContext()
spriteContext.output = "images"
spriteContext.images = {"image"}
spriteContext.channels = {image = {1}}
spriteContext.values = {0.0}
spriteContext.blend = "add"
spriteContext.seamless = false

level = 1 -- Level 0 is reserved for the background
layer = 1
shape = spriteIt.getAttributeValue("shape")
index = spriteIt.getAttributeValue("index")
parameter1 = spriteIt.getAttributeValue("parameter1")
parameter2 = spriteIt.getAttributeValue("parameter2")
parameter3 = spriteIt.getAttributeValue("parameter3")
parameter4 = spriteIt.getAttributeValue("parameter4")
value = {spriteIt.getAttributeValue("value")}
mask1 = spriteIt.getAttributeValue("mask1")
mask2 = spriteIt.getAttributeValue("mask2")
mask3 = spriteIt.getAttributeValue("mask3")
mask4 = spriteIt.getAttributeValue("mask4")
modifier1 = spriteIt.getAttributeValue("modifier1")
modifier2 = spriteIt.getAttributeValue("modifier2")
modifier3 = spriteIt.getAttributeValue("modifier3")
modifier4 = spriteIt.getAttributeValue("modifier4")
hsloVariation = {0.0, 0.0, 0.0, 0.0}

tm = matrix2()

shapeIndex = spriteIt.getShapeIndex(shape)

parameters = {parameter1, parameter2, parameter3, parameter4}
modifiers = {0.0, 0.0, 0.0, 0.0}
mask = {mask1, mask2, mask3, mask4}
modifiers = {modifier1, modifier2, modifier3, modifier4}

spriteContext:pushSprite(level, layer, tm, shapeIndex, index, parameters, modifiers, value, mask, hsloVariation)

Sprite Properties

Level

The sprites are organized in layers and levels. These properties define the order in which the sprites are rendered, and their intensity in the final image.

Layer

The sprites are organized in layers and levels. These properties define the order in which the sprites are rendered, and their intensity in the final image.

Transformation Matrix

The transformation matrix (tm) sets the offset, rotation and scale of the sprite.

The transformation matrix is a parameter of type matrix2.

Shape

The texture of the quad is defined by the shape, the index, and thes parameters of the sprite.

Sprite It supports the rendering of these shapes:

The index and the parameters modify the shape.

Image

The image shape renders an input image.

Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets what input image is rendered. Parameters: sets the UV coordinates of the lower-left and upper-right corners of the image.

Brick

The brick shape renders a rectangular brick with a profiled edge.

Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets the profile of the edges (see below Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. transition
  2. aspect
  3. slant X
  4. slant Y

Bump

The bump shape renders a rounded bump with a profiled edge.

Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets the profile of the edges (see Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. transition
  2. ignored
  3. slant X
  4. slant Y

Ring

The ring shape renders a ring with a profiled edge.

Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets the profile of the edges (see below Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. inner radius
  2. bias
  3. slant X
  4. slant Y

Waves

The waves shape renders waves with a profiled curve.

Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets the profile of the waves curve (see below Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. number of waves
  2. bias
  3. slant X
  4. slant Y

Polygon

The polygon shape renders an irregular polygon with 3 to 8 sides.

Shape<em>Polygon</em>1 Shape<em>Polygon</em>1 Shape<em>Polygon</em>1 Shape<em>Brick</em>1

Index: sets the profile of the polygon (see below Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. random seed
  2. number of sides
  3. irregularity
  4. transition

Irregular

The irregular shape renders a rounded shape with 4 radii.

Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1 Shape<em>Brick</em>1

Index: sets the profile of the edges (see Shape Profiles).

Parameters: parameters is a table with 4 numbers that set:

  1. sets the radii of the shape from a predefined random array.
  2. irregularity
  3. transition
  4. slant

Ramp

The ramp shape renders a two sided ramp with curved profiles.

Shape<em>Ramp</em>1 Shape<em>Ramp</em>2 Shape<em>Ramp</em>3 Shape<em>Ramp</em>4

Index: sets the profile of the curved ramps.

Parameters: parameters is a table with 4 numbers that set:

  1. left side width
  2. right side width
  3. slant bottom
  4. slant top

Index

The profile of most shapes is computed by a function with the requested graph:

1. Linear

Profile 1 Linear Shape 1 Linear

2. Smooth

Profile 2 Smooth Shape 2 Smooth

3. Arc

Profile 3 Arc Shape

4. Arc In

Profile 4 Arc Inverted Shape 4 Arc In

5. Polynomial

Profile 5 Polynomial Shape 5 Polynomial

6. Polynomial In

Profile 6 Polynomial In Shape 6 Polynomial In

Beyond 6. Higher Degree Polynomials

Any index higher than 6 makes a polynomial of higher degree:

Shape 11 Polynomial Shape 12 Polynomial In

Parameters

This is a 4 elements table. The Shape section describes what the parameters are for each shape.

Modifiers

The modifiers are set in a 4 elements table and they modify the shape of the sprite in the horizontal and vertical axes. Items 1 and 2 taper the shape in the X or Y axis. Items 3 and 4 scale down one side of the shape towards the middle of the sprite. Modifiers values range from -1.0 to 1.0.

Slant Zero All modifiers are 0.0

Slant Zero Item 1 Taper X = 0.5

Slant Zero Item 2 Taper Y = 0.5

Slant Zero Item 3 Flip X = 0.5

Slant Zero Item 4 Flip Y = 0.5

Mask

Mask is a 4 elements table that lowers the value of the sprite.

Item 1 - Dome Mask

Slant Zero Positive.

Slant Zero Zero.

Slant Zero Negative.

Item 2 - Pyramid Mask

Item 3 - Horizontal Slant Mask

Slant Zero Slant X = 0.0

Slant ZeroSlant X = -1.0

Slant Zero Slant X = 1.0

Item 4 - Vertical Slant Mask

Slant Zero Slant X = 0.0

Slant Zero Slant Y = -1.0

Slant Zero Slant Y = 1.0

Values

The values table sets the shades of the sprite.

The values table must match the Sprite Context values table.