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.
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)
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.
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.
The transformation matrix (tm) sets the offset, rotation and scale of the sprite.
The transformation matrix is a parameter of type matrix2.
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.
The image shape renders an input image.
Index: sets what input image is rendered. Parameters: sets the UV coordinates of the lower-left and upper-right corners of the image.
The brick shape renders a rectangular brick with a profiled edge.
Index: sets the profile of the edges (see below Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The bump shape renders a rounded bump with a profiled edge.
Index: sets the profile of the edges (see Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The ring shape renders a ring with a profiled edge.
Index: sets the profile of the edges (see below Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The waves shape renders waves with a profiled curve.
Index: sets the profile of the waves curve (see below Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The polygon shape renders an irregular polygon with 3 to 8 sides.
Index: sets the profile of the polygon (see below Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The irregular shape renders a rounded shape with 4 radii.
Index: sets the profile of the edges (see Shape Profiles).
Parameters: parameters is a table with 4 numbers that set:
The ramp shape renders a two sided ramp with curved profiles.
Index: sets the profile of the curved ramps.
Parameters: parameters is a table with 4 numbers that set:
The profile of most shapes is computed by a function with the requested graph:
1. Linear
2. Smooth
3. Arc
4. Arc In
5. Polynomial
6. Polynomial In
Beyond 6. Higher Degree Polynomials
Any index higher than 6 makes a polynomial of higher degree:
This is a 4 elements table. The Shape section describes what the parameters are for each shape.
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.
All modifiers are 0.0
Item 1 Taper X = 0.5
Item 2 Taper Y = 0.5
Item 3 Flip X = 0.5
Item 4 Flip Y = 0.5
Mask is a 4 elements table that lowers the value of the sprite.
Positive.
Zero.
Negative.
Slant X = 0.0
Slant X = -1.0
Slant X = 1.0
Slant X = 0.0
Slant Y = -1.0
Slant Y = 1.0
The values table sets the shades of the sprite.
The values table must match the Sprite Context values table.