diff options
| author | Amir Rajan <[email protected]> | 2020-11-13 01:29:16 -0600 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2020-11-13 01:29:16 -0600 |
| commit | 128fa1d90cea6289605a49daf56a0cbb72e2dd28 (patch) | |
| tree | 5cfdb499d275e2b43075e4d6a076365fc58ff0f7 /samples/07_advanced_rendering | |
| parent | 05cbef7fb8224332795e5685be499d81d20e7d93 (diff) | |
| download | dragonruby-game-toolkit-contrib-128fa1d90cea6289605a49daf56a0cbb72e2dd28.tar.gz dragonruby-game-toolkit-contrib-128fa1d90cea6289605a49daf56a0cbb72e2dd28.zip | |
synced from DRGTK 1.27
Diffstat (limited to 'samples/07_advanced_rendering')
| -rw-r--r-- | samples/07_advanced_rendering/06_pixel_arrays/app/main.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/samples/07_advanced_rendering/06_pixel_arrays/app/main.rb b/samples/07_advanced_rendering/06_pixel_arrays/app/main.rb new file mode 100644 index 0000000..12291c4 --- /dev/null +++ b/samples/07_advanced_rendering/06_pixel_arrays/app/main.rb @@ -0,0 +1,41 @@ +$gtk.reset + +def tick args + args.state.posinc ||= 1 + args.state.pos ||= 0 + args.state.rotation ||= 0 + + dimension = 10 # keep it small and let the GPU scale it when rendering the sprite. + + # Set up our "scanner" pixel array and fill it with black pixels. + args.pixel_array(:scanner).width = dimension + args.pixel_array(:scanner).height = dimension + args.pixel_array(:scanner).pixels.fill(0xFF000000, 0, dimension * dimension) # black, full alpha + + # Draw a green line that bounces up and down the sprite. + args.pixel_array(:scanner).pixels.fill(0xFF00FF00, dimension * args.state.pos, dimension) # green, full alpha + + # Adjust position for next frame. + args.state.pos += args.state.posinc + if args.state.posinc > 0 && args.state.pos >= dimension + args.state.posinc = -1 + args.state.pos = dimension - 1 + elsif args.state.posinc < 0 && args.state.pos < 0 + args.state.posinc = 1 + args.state.pos = 1 + end + + # New/changed pixel arrays get uploaded to the GPU before we render + # anything. At that point, they can be scaled, rotated, and otherwise + # used like any other sprite. + w = 100 + h = 100 + x = (1280 - w) / 2 + y = (720 - h) / 2 + args.outputs.background_color = [64, 0, 128] + args.outputs.primitives << [x, y, w, h, :scanner, args.state.rotation].sprite + args.state.rotation += 1 + + args.outputs.primitives << args.gtk.current_framerate_primitives +end + |
