diff options
| author | Amir Rajan <[email protected]> | 2019-09-06 15:33:10 -0500 |
|---|---|---|
| committer | Amir Rajan <[email protected]> | 2019-09-06 15:33:10 -0500 |
| commit | 220c3f0ed4a323d5d7e354c7f1b7ff1e8b16c4e9 (patch) | |
| tree | ea88e9c1425389a0fe4df8fb3d411a7c5fed1542 /deploy_template/mygame/documentation/04-lines.md | |
| parent | 9c2ce126dba8a4c3ada82e5f4bd6637b1fa92ab0 (diff) | |
| download | dragonruby-game-toolkit-contrib-220c3f0ed4a323d5d7e354c7f1b7ff1e8b16c4e9.tar.gz dragonruby-game-toolkit-contrib-220c3f0ed4a323d5d7e354c7f1b7ff1e8b16c4e9.zip | |
Added deploy_template to contribe.
Diffstat (limited to 'deploy_template/mygame/documentation/04-lines.md')
| -rw-r--r-- | deploy_template/mygame/documentation/04-lines.md | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/deploy_template/mygame/documentation/04-lines.md b/deploy_template/mygame/documentation/04-lines.md new file mode 100644 index 0000000..03c1abc --- /dev/null +++ b/deploy_template/mygame/documentation/04-lines.md @@ -0,0 +1,108 @@ +# Lines + +Lines are 1 pixel wide and can be diagonal. + +## Sample Apps Related to Line Usage (ordered by size of codebase increasing) + +- 01_api_02_lines +- 01_api_99_tech_demo (includes recording) +- 06_coordinate_systems (includes recording) +- 19_lowrez_jam_01_hello_world +- 99_sample_game_pong (includes recording) + +## Minimum Code + +Creates a black line from the bottom left corner to the top right corner. + +```ruby +# X1 Y1 X2 Y2 +args.outputs.lines << [ 0, 0, 1280, 720] +``` + +Creates a black vertical line through the center of the scene. + +```ruby +# X1 Y1 X2 Y2 +args.outputs.lines << [ 640, 0, 640, 720] +``` + +Creates a black horizontal line through the center of the scene. + +```ruby +# X1 Y1 X2 Y2 +args.outputs.lines << [ 0, 360, 1280, 360] +``` + +## RGBA - Colors and Alpha + +The value for the color and alpha is an number between `0` and `255`. The +alpha property is optional and will be set to `255` if not specified. + +Creates a green horizontal line through the center of the scene with an opacity of 50%. + +```ruby +# X1 Y1 X2 Y2 RED GREEN BLUE ALPHA +args.outputs.lines << [ 0, 360, 1280, 360, 0, 255, 0, 128] +``` + +Creates a green vertical line through the center of the scene. +The opacity is excluded because it's 100% opaque (which has a value of 255). + +```ruby +# X1 Y1 X2 Y2 RED GREEN BLUE +args.outputs.lines << [ 640, 0, 640, 720, 0, 255, 0] +``` + +## Hash (Advanced) + +If you want a more readable invocation. You can use the following hash to create a line. +Any parameters that are not specified will be given a default value. The keys of the hash can +be provided in any order. + +```ruby +args.outputs.lines << { + x: 0, + y: 0, + x2: 1280, + y2: 720, + r: 0, + g: 255, + b: 0, + a: 255 +} +``` + +## Duck Typing (Advanced) + +You can also create a class with line properties and render it as a primitive. +ALL properties must on the class. ADDITIONALLY, a method called `primitive_marker` +must be defined on the class. + +Here is an example: + +```ruby +# Create type with ALL line properties AND primitive_marker +class Line + attr_accessor :x, :y, :x2, :y2, :r, :g, :b, :a + + def primitive_marker + :line + end +end + +# Inherit from type +class VerticalLine < Line + + # constructor + def initialize x, y, h + self.x = x + self.y = y + self.x2 = x + self.y2 = y + h + end +end + +# render line + +args.outputs.lines << VerticalLine.new(10, 10, 100) +``` |
