diff options
| author | Amir Rajan <[email protected]> | 2020-09-11 02:02:01 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-09-11 02:02:57 -0500 |
| commit | 33ec37b141e896b47ed642923fd33b0c658ae9fb (patch) | |
| tree | a40d3e5d41beeb06508200078f6f26b0ee57d6a4 /samples/07_advanced_rendering/01_simple_render_targets | |
| parent | 958cf43779d2bf528869e80511c4c4f2a433b2db (diff) | |
| download | dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.tar.gz dragonruby-game-toolkit-contrib-33ec37b141e896b47ed642923fd33b0c658ae9fb.zip | |
synced samples
Diffstat (limited to 'samples/07_advanced_rendering/01_simple_render_targets')
| -rw-r--r-- | samples/07_advanced_rendering/01_simple_render_targets/app/main.rb | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/samples/07_advanced_rendering/01_simple_render_targets/app/main.rb b/samples/07_advanced_rendering/01_simple_render_targets/app/main.rb new file mode 100644 index 0000000..8670453 --- /dev/null +++ b/samples/07_advanced_rendering/01_simple_render_targets/app/main.rb @@ -0,0 +1,52 @@ +def tick args + # args.outputs.render_targets are really really powerful. + # They essentially allow you to create a sprite programmatically and cache the result. + + # Create a render_target of a :block and a :gradient on tick zero. + if args.state.tick_count == 0 + args.render_target(:block).solids << [0, 0, 1280, 100] + + # The gradient is actually just a collection of black solids with increasing + # opacities. + args.render_target(:gradient).solids << 90.map_with_index do |x| + 50.map_with_index do |y| + [x * 15, y * 15, 15, 15, 0, 0, 0, (x * 3).fdiv(255) * 255] + end + end + end + + # Take the :block render_target and present it horizontally centered. + # Use a subsection of the render_targetd specified by source_x, + # source_y, source_w, source_h. + args.outputs.sprites << { x: 0, + y: 310, + w: 1280, + h: 100, + path: :block, + source_x: 0, + source_y: 0, + source_w: 1280, + source_h: 100 } + + # After rendering :block, render gradient on top of :block. + args.outputs.sprites << [0, 0, 1280, 720, :gradient] + + args.outputs.labels << [1270, 710, args.gtk.current_framerate, 0, 2, 255, 255, 255] + tick_instructions args, "Sample app shows how to use render_targets (programmatically create cached sprites)." +end + +def tick_instructions args, text, y = 715 + return if args.state.key_event_occurred + if args.inputs.mouse.click || + args.inputs.keyboard.directional_vector || + args.inputs.keyboard.key_down.enter || + args.inputs.keyboard.key_down.escape + args.state.key_event_occurred = true + end + + args.outputs.debug << [0, y - 50, 1280, 60].solid + args.outputs.debug << [640, y, text, 1, 1, 255, 255, 255].label + args.outputs.debug << [640, y - 25, "(click to dismiss instructions)" , -2, 1, 255, 255, 255].label +end + +$gtk.reset |
