Ruby_for_Dragons

An unofficial companion to the DragonRuby documentation

View on GitHub
Home DragonRuby API Documentation Quick Answers Kota’s Cheatsheet Sitemap

Kota's Cheatsheet

A quick collection of some of the most used features.

By Kota

Basic App

def tick args
  args.outputs.solids << {
    x: 300, y:200,
    w: 30, h: 30
  }
end

Primitive Types

Rendered Bottom to Top

solids
static_solids
sprites
static_sprites
primitives
static_primitives
labels
static_labels
lines
static_lines
borders
static_borders

args.outputs.solids

args.outputs.solids << {
  x: x_pos, y: y_pos,
  w: width, h: height,
  r: red, g: green,
  b: blue, a: alpha
}

args.outputs.solids (for triangles)

args.outputs.sprites << {
  x: x, y: y, r: r, g: g, b: b, a: a,
  x3: 200, y3: 200, # mark a triangle
}```

## args.outputs.sprites
```rb
args.outputs.sprites << {
  x: x, y: y, w: w, h: h, r: r, g: g, b: b, a: a,
  path: 'sprites/circle/red.png', # path to the source image
  angle: rotation_degrees,
  source_x: x_from_image,
  source_y: y_from_image,
  source_w: w_from_image,
  source_h: h_from_image,
  flip_vertically: true_or_false,
  flip_horizontally: true_or_false,
  angle_anchor_x: 0.3, # 0 = left, 1 = right, center of rotation
  angle_anchor_y: 0.3, # 0 = left, 1 = right, center of rotation
  blendmode_enum: 0 # see blendmode section
}

args.outputs.sprites (for triangles)

args.outputs.sprites << {
  x: x, y: y, r: r, g: g, b: b, a: a,
  x3: 200, y3: 200, # mark a triangle
  path: 'sprites/circle/red.png', # path to the source image
  source_x: x_from_image,  source_y: y_from_image,  # defaults to `0`
  source_x2: x_from_image, source_y2: y_from_image, # triangle image fill (mandatory)
  source_x3: x_from_image, source_y3: y_from_image,  # triangle image fill (mandatory)
  blendmode_enum: 0 # see blendmode section (I'm unsure of this one)
}```
  

## args.outputs.primitives
This example is for a `solid` primitive. Other types include

```rb
:solid
:sprite
:label
:line
:border
args.outputs.primitives << {
  x: x_pos, y: y_pos,
  w: width, h: height,
  r: red, g: green,
  b: blue, a: alpha,
  primitive_marker: :solid
}

args.outputs.labels

args.outputs.labels << {
  x: x, y: y, r: r, g: g, b: b, a: a,
  alignment_enum: 0, # 0 = left, 1 = center, 2 = right, horizontal alignment
  vertical_alignment_enum: 0, # 0 = top, 1 = center, 2 = bottom
  font: 'font.ttf', # path to font file
  size_enum: 0 # less than 0 is smaller, more than 0 is larger
}

args.outputs.lines

args.outputs.lines << {
  x: 0, y: 0, # point 1 coordinates
  w: 100, h: 100, # relative coordinates
  x2: 100, y2: 100, # point 2 coordinates
  r: r, g: g, b: b, a: a
}

args.outputs.borders

Same arguments as solids.

args.outputs.borders << {
  x: x_pos, y: y_pos,
  w: width, h: height,
  r: red, g: green,
  b: blue, a: alpha
}

Render Targets

To use a render target, use args.outputs.sprites with :render_target_name as the path.

args.outputs[:render_target_name].primitives << some_primitive
# alternatively
args.render_target(:render_target_name).primitives << some_primitive

args.outputs.sprites << {
  x: x, y: y, w: w, h: h, r: r, g: g, b: b, a: a,
  path: :render_target_name
}

State

Store arbitrary data between ticks.

args.state.game_name = "Name of the Game"

Fullscreen

args.gtk.set_window_fullscreen true # or false

Text Size

w, h = args.gtk.calcstringbox(string, size_enum, path_to_font)

Inputs

args.inputs.mouse

args.inputs.mouse = {
  :x,
  :y,
  :click,
  :down,
  :previous_click,
  :up,
  :inside_rect?,
  :inside_circle?,
  :moved,
  :button_left,
  :button_right,
  :button_middle,
  :button_bits,
  :wheel
}

Directional

args.inputs.left
args.inputs.right
args.inputs.up
args.inputs.down

args.inputs.keyboard

args.inputs.keyboard = {
  :key_held.KEY,
  :key_down.KEY,
  :key_up.KEY,
  :KEY,
  :up_down,
  :left_right,
  :raw_key
}

Background Color

args.outputs.background_color = [red, green, blue]

Sound Output

Using an .ogg file will cause the sound to loop.

args.outputs.sound << 'sounds/file.ogg'

For non-looping sounds:

args.gtk.queue_sound << 'sounds/file.ogg'

Cursor Controls

args.show_cursor
args.hide_cursor
args.cursor_shown?

See Also

matrix
geometry
grid
write_file
read_file
audio
server
http