The following code renders a sprite
and a solid
with an alpha. But the solid
renders below the sprite
. How do I get the solid to render above the sprite
?
def tick args
args.outputs.sprites << {
x: 100,
y: 100,
w: 50,
h: 60,
path: 'sprites/square-red.png'
}
args.outputs.solids << {
x: 0,
y: 0,
w: 1280,
h: 720,
r: 80,
g: 80,
b: 80,
a: 128
}
end
The default render order (bottommost to topmost) for primitives is:
solids
sprites
primitives
labels
lines
borders
To have a solid
render over a sprite
, you must use args.outputs.primitives
which will render in the order that you add to the collection (regardless of primitive type):
def tick args
# step 1: use .primitives instead of .sprites
args.outputs.primitives << {
x: 100,
y: 100,
w: 50,
h: 60,
path: 'sprites/square-red.png'
}.sprite # step 2: invoke the .sprite function on the primitive
# step 3: use .primitives instead of .solids
args.outputs.primitives << {
x: 0,
y: 0,
w: 1280,
h: 720,
r: 80,
g: 80,
b: 80,
a: 128
}.solids # step 4: mark the primitive as a solid
end
This begs the question:
Should I use
.primitives
for everything?
That is totally fine to do frankly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With