109
loading...
This website collects cookies to deliver better user experience
args
(always accessible with $gtk.args
... because there's more than one way!)<<
on args.outputs
- like args.outputs.sprites
or args.outputs.sounds
.def tick args
args.outputs.solids << [100, 200, 300, 400]
end
tick
method if it's not explicitly defined.)args.outputs
as arrays - essentially positional arguments.args.outputs.solids << [100, 200, 300, 400]
args.outputs.solids << {
x: 100,
y: 200,
w: 300, # width
h: 400 # height
}
args.outputs.solids << {
x: 100,
y: 200,
w: 300,
h: 400,
r: 255, # red
g: 200, # green
b: 255, # blue
a: 100, # alpha
blendmode_enum: 0 # blend mode
}
args.outputs.solids
, args.outputs.labels
, args.outputs.sprites
, etc., we can output a hash to args.outputs.primitives
but mark it as the right primitive "type":args.outputs.primitives << {
x: 100,
y: 200,
w: 300,
h: 400,
r: 255, # red
g: 200, # green
b: 255, # blue
a: 100, # alpha
blendmode_enum: 0 # blend mode
}.solid!
primitive_marker
that returns the type of primitive.class ACoolSolid
attr_reader :x, :y, :w, :h, :r, :g, :b, :a, :blendmode_enum
def initialize x, y, w, h
@x = x
@y = y
@w = w
@h = h
end
def primitive_marker
:solid
end
end
def tick args
args.outputs.primitives << ACoolSolid.new(100, 200, 300, 400)
end
attr_reader
, you can use attr_sprite
instead which is a DragonRuby shortcut method to do the same thing.primitives
just hold things like solids, sprites, labels...?primitives
enables better control over render order.args.outputs.primitives
we can do it:def tick args
a_solid = {
x: 100,
y: 200,
w: 300,
h: 400
}.solid!
a_sprite = {
x: 100,
y: 200,
w: 500,
h: 500,
path: 'metadata/icon.png'
}.sprite!
args.outputs.primitives << a_sprite << a_solid
end
args.outputs.sprites
, etc. get cleared after each call to tick
. So every tick we have to recreate all the objects and pass them in to args.outputs
. Seems wasteful, right? Yes, it is!args.outputs
destroyed or modified in some way?class ACoolSolid
attr_reader :x, :y, :w, :h, :r, :g, :b, :a, :blendmode_enum
def initialize x, y, w, h
@x = x
@y = y
@w = w
@h = h
end
def primitive_marker
:solid
end
end
$a_solid = ACoolSolid.new(10, 20, 30, 40)
def tick args
args.outputs.primitives << $a_solid
end
args.outputs.primitives
each time. Surely that is unnecessary?args.outputs
(e.g. args.outputs.static_solids
) that do not get cleared every tick.