The Sprite It module defines a set of nodes that can be instanced and connected into graphs. These nodes have a set of parameters that define how they behave when the graph is evaluated.
There are nodes that divide the image area into smaller regions, nodes that use conditions to decide what branches to evaluate, nodes that set the layers, and nodes that add new sprites to the context.
All nodes have a set of members that define their behavior when evaluated, and these members can be set as functions that are evaluated to add a higher level of control to the node behavior during evaluation.
SpawnNode. Spawns a new sprite and adds it to the sprite context.
TilesNode. Tessellates the area with rectangular tiles and calls evaluate on its child node.
PoissonNode. Creates a Poisson Disc Sampling that tightly packs discs without overlapping.
BranchNode. Divides the area in 4 quadrants and calls evaluate on each of the 4 connected nodes. This node increases the state level property.
IteratorNode. Calls evaluate on its connected node a number of times.
SwitchNode. Calls evaluate on its child node if the condition property is true.
CombineNode. Has two children nodes, and evaluates them both. This node sets the state layer property, allowing the lower nodes to organize the sprites in layers.
All node members can be defined as values (number, vector, etc), or functions that return these values.
As the graph is evaluated, Sprite It keeps a structure with the current conditions for the node to be evaluated. This structure is the state and it has the following members:
box A sub region of the image area. Sprites will be spawned at the center of this area, and with this area's size. Type: box2
level Current level. Levels are set by the Branch nodes. Type: integer
layer Current layer. Layers are set by the Combine node. Type: integer
iteration Current iteration. Iterations are set by nodes like Branch and Array. Type: integer
iterations Total number of iterations. Iterations are set by nodes like Branch and Array. Type: integer
Spawns a new sprite and adds it to the Sprite Context. The new sprite is positioned at the center of the state box, and it's size is the state box size.
name Type: string
shape Type: string Valid options: image, brick, bump, ring, waves, irregular, ramp Sets the shape property of the sprite. Setting this member to empty ("") or any other invalid value stops the generation of the sprite.
index Type: integer Sets the index property of the sprite.
parameters Type: float[4] Sets the parameters property of the sprite.
mask Type: float Sets the mask property of the sprite.
offset Type: vector2 Sets the vector that offsets the sprite. The offset is relative to the center of the state box.
rotation Type: float Rotates the sprite (in radians).
scale Type: vector2 Scales the sprite. The scale is relative to the size of the state box.
values Type: float[n] Sets the values of the image channels of the sprite.
Tessellates the area with rectangular tiles and calls evaluate on its child node. This node sets state iterations and iteration properties.
name Type: string
tilesX Number of tiles in x. Type: integer
tilesY Number of tiles in Y. Type: integer
setNode(node) Sets the node that will be evaluated for each tile.
Creates a Poisson Disc Sampling that tightly packs discs without overlapping.
name
Type: string
radius
Base radius of the discs.
Type: integer
iterations
Number of times the algorithm tries to find a location for a new disc from a previous disc location.
Type: integer
maxScale
Maximum scale of the discs in the sampling. Value from 1.0 to 3.5.
Type: float
The branch node divides the area in 4 branches and calls evaluate on each of the 4 connected nodes.
name Type: string
offset Type: vector2 Sets the vector that offsets the branch. This offset is relative to the state box.
setNode(branch, node) Sets the node specified by the branch identifier:
setNodes(bottom left node, bottom right node, top left node, top right node) Sets all branch nodes.
setSpawnNode(node) Sets the spawn node.
Has two connected nodes, and calls evaluate on the one or the other given a condition value.
condition Type: boolean The variable used to decide if to evaluate one node or the other.
setNodeTrue(node) Sets the node that will be evaluated if the condition is true.
setNodeFalse(node) Sets the node that will be evaluated if the condition is false.
The iterator node calls its child node a given number of times.
The iterator node sets the state iterations and iteration values.
iterations Type: integer The number of times the iterator node will evaluate its child node.
setNode(node) Sets the node.
The combine node mixes two nodes, A and B, and sets the layers parameter of the state.
layerA Type: integer Sets the layer of the state when evaluating node A.
layerB Type: integer Sets the layer of the state when evaluating node B.
setNodeA(node) Sets node A.
setNodeB(node) Sets node B.
Lua is a weakly typed language, and variables can represent values or functions. Setting a node member as a function allows nodes to return values that depend on the state of the evaluation.
Member as value
spawnNode.rotation = 0.1
Member as function
function SpriteRotation(spriteContext, state)
local v = 2.0 * math.pi * math.random()
return v
end
smoothSpawn.rotation = SpriteRotation
The function takes two arguments, the Sprite Context and the current State.
The returned type of the function must be of the same type as the member.