Module: Gosu

Defined in:
rdoc/gosu.rb

Defined Under Namespace

Classes: Channel, Color, Font, GLTexInfo, Image, Sample, Song, TextInput, Window

Constant Summary collapse

MAJOR_VERSION =

The first component of the version.

:an_integer
MINOR_VERSION =

The second component of the version.

:an_integer
POINT_VERSION =

The third component of the version.

:an_integer
VERSION =

A version string of the form “0.1.2”, “0.1.2.3” or “0.1.2pre4”.

:a_string
LICENSES =

A block of legal copy that your game is obliged to display somewhere.

:a_string
KB_0…KB_9 =
:an_integer
KB_A…KB_Z =
:an_integer
KB_APOSTROPHE =
:an_integer
KB_BACKSLASH =
:an_integer
KB_BACKSPACE =
:an_integer
KB_BACKTICK =
:an_integer
KB_COMMA =
:an_integer
KB_DELETE =
:an_integer
KB_DOWN =
:an_integer
KB_END =
:an_integer
KB_PRINT_SCREEN =
:an_integer
KB_SCROLL_LOCK =
:an_integer
KB_PAUSE =
:an_integer
KB_ENTER =

This is the key on the numpad.

:an_integer
KB_EQUALS =
:an_integer
KB_ESCAPE =
:an_integer
KB_F1…KB_F12 =
:an_integer
KB_HOME =
:an_integer
KB_INSERT =
:an_integer
KB_ISO =
:an_integer
KB_LEFT =
:an_integer
KB_LEFT_ALT =
:an_integer
KB_LEFT_BRACKET =
:an_integer
KB_LEFT_CONTROL =
:an_integer
KB_LEFT_META =
:an_integer
KB_LEFT_SHIFT =
:an_integer
KB_MINUS =
:an_integer
KB_NUMPAD_0…KB_NUMPAD_9 =
:an_integer
KB_NUMPAD_DELETE =
:an_integer
KB_NUMPAD_DIVIDE =
:an_integer
KB_NUMPAD_MINUS =
:an_integer
KB_NUMPAD_MULTIPLY =
:an_integer
KB_NUMPAD_PLUS =
:an_integer
KB_PAGE_DOWN =
:an_integer
KB_PAGE_UP =
:an_integer
KB_PERIOD =
:an_integer
KB_RETURN =

This is the key above the right shift key.

:an_integer
KB_RIGHT =
:an_integer
KB_RIGHT_ALT =
:an_integer
KB_RIGHT_BRACKET =
:an_integer
KB_RIGHT_CONTROL =
:an_integer
KB_RIGHT_META =
:an_integer
KB_RIGHT_SHIFT =
:an_integer
KB_SEMICOLON =
:an_integer
KB_SLASH =
:an_integer
KB_CAPS_LOCK =
:an_integer
KB_SPACE =
:an_integer
KB_TAB =
:an_integer
KB_UP =
:an_integer
MS_LEFT =
:an_integer
MS_MIDDLE =
:an_integer
MS_RIGHT =
:an_integer
MS_WHEEL_DOWN =
:an_integer
MS_WHEEL_UP =
:an_integer
MS_OTHER_0…MS_OTHER_7 =
:an_integer
GP_BUTTON_0…GP_BUTTON_15 =
:an_integer
GP_LEFT_STICK_X_AXIS =
:an_integer
GP_RIGHT_STICK_X_AXIS =
:an_integer
GP_LEFT_STICK_Y_AXIS =
:an_integer
GP_RIGHT_STICK_Y_AXIS =
:an_integer
GP_LEFT_TRIGGER_AXIS =
:an_integer
GP_RIGHT_TRIGGER_AXIS =
:an_integer
GP_DPAD_DOWN =
:an_integer
GP_DPAD_LEFT =
:an_integer
GP_DPAD_RIGHT =
:an_integer
GP_DPAD_UP =
:an_integer
GP_DOWN =
:an_integer
GP_LEFT =
:an_integer
GP_RIGHT =
:an_integer
GP_UP =
:an_integer
GP_0_BUTTON_0…GP_3_BUTTON_15 =
:an_integer
GP_0_LEFT_STICK_X_AXIS…GP_3_LEFT_STICK_X_AXIS =
:an_integer
GP_0_RIGHT_STICK_X_AXIS…GP_3_RIGHT_STICK_X_AXIS =
:an_integer
GP_0_LEFT_STICK_Y_AXIS…GP_3_LEFT_STICK_Y_AXIS =
:an_integer
GP_0_RIGHT_STICK_Y_AXIS…GP_3_RIGHT_STICK_Y_AXIS =
:an_integer
GP_0_LEFT_TRIGGER_AXIS…GP_3_LEFT_TRIGGER_AXIS =
:an_integer
GP_0_RIGHT_TRIGGER_AXIS…GP_3_RIGHT_TRIGGER_AXIS =
:an_integer
GP_0_DPAD_DOWN…GP_3_DPAD_DOWN =
:an_integer
GP_0_DPAD_LEFT…GP_3_DPAD_LEFT =
:an_integer
GP_0_DPAD_RIGHT…GP_3_DPAD_RIGHT =
:an_integer
GP_0_DPAD_UP…GP_3_DPAD_UP =
:an_integer
GP_0_DOWN…GP_3_DOWN =
:an_integer
GP_0_LEFT…GP_3_LEFT =
:an_integer
GP_0_RIGHT…GP_3_RIGHT =
:an_integer
GP_0_UP…GP_3_UP =
:an_integer

Drawing primitives collapse

Manipulating the current drawing context collapse

Class Method Summary collapse

Class Method Details

.angle(x1, y1, x2, y2) ⇒ Float

Returns the angular distance from (x1, y1) to (x1, y2) in degrees, where 0.0 is up. Returns 0 if both points are equal.

Parameters:

  • x1 (Float)
  • y1 (Float)
  • x2 (Float)
  • y2 (Float)

Returns:

  • (Float)

    the angular distance from (x1, y1) to (x1, y2) in degrees, where 0.0 is up. Returns 0 if both points are equal.



1349
# File 'rdoc/gosu.rb', line 1349

def angle(x1, y1, x2, y2); end

.angle_diff(angle1, angle2) ⇒ Float

Returns the shortest angular distance from angle1 to angle2. This can be negative if counter-clockwise rotation would yield a shorter distance.

Parameters:

  • angle1 (Float)
  • angle2 (Float)

Returns:

  • (Float)

    the shortest angular distance from angle1 to angle2. This can be negative if counter-clockwise rotation would yield a shorter distance.



1355
# File 'rdoc/gosu.rb', line 1355

def angle_diff(angle1, angle2); end

.available_height(window = nil) ⇒ Integer

All windows larger than this size will automatically be shrunk to fit.

Returns:

  • (Integer)

    the maximum height (in ‘points’) that is available for a non-fullscreen Window.



1397
# File 'rdoc/gosu.rb', line 1397

def available_height(window = nil); end

.available_width(window = nil) ⇒ Integer

All windows larger than this size will automatically be shrunk to fit.

Returns:

  • (Integer)

    the maximum width (in ‘points’) that is available for a non-fullscreen Window.



1393
# File 'rdoc/gosu.rb', line 1393

def available_width(window = nil); end

.axis(id) ⇒ Float

Returns the value for the specified gamepad axis in the range -1.0..1.0 for joysticks and 0.0..1.0 for triggers.

Examples:

Gosu.axis(Gosu::GP_0_LEFT_STICK_Y_AXIS) #=> 0.75

Parameters:

  • id (Integer)

Returns:

  • (Float)


1044
# File 'rdoc/gosu.rb', line 1044

def axis(id); end

.button_down?(id) ⇒ true, false

Returns whether the button ‘id` is currently pressed. Button states are updated once per tick, so repeated calls during the same tick will always yield the same result.

Returns:

  • (true, false)

    whether the button is currently pressed.

See Also:



1012
# File 'rdoc/gosu.rb', line 1012

def button_down?(id); end

.button_id_to_char(id) ⇒ String?

Note:

For real text input, look at TextInput instead.

Returns the character a button usually produces, if any.

Parameters:

  • id (Integer)

    the button’s platform-defined id.

Returns:

  • (String?)

    the character the button usually produces.

See Also:



1312
# File 'rdoc/gosu.rb', line 1312

def button_id_to_char(id); end

.button_name(id) ⇒ String?

Returns the name of a Gosu::KB_* constant. Returns nil if no name is found.

Examples:

Gosu.button_name(Gosu::KB_SPACE) #=> "Space"

Parameters:

  • id (Integer)

Returns:

  • (String, nil)


1023
# File 'rdoc/gosu.rb', line 1023

def button_name(id); end

.char_to_button_id(char) ⇒ Integer?

Returns the button that usually produces a character, if any.

Parameters:

  • char (String)

    the character to query.

Returns:

  • (Integer?)

    the button that usually produces the character.

See Also:



1323
# File 'rdoc/gosu.rb', line 1323

def char_to_button_id(char); end

.clip_to(x, y, w, h) { ... } ⇒ void

This method returns an undefined value.

Masks the drawing area inside the block.

Parameters:

  • x (Float)

    the X coordinate of the top left corner,.

  • y (Float)

    the Y coordinate of the top left corner.

  • w (Float)

    the width of the clipping area.

  • h (Float)

    the height of the clipping area.

Yields:

  • rendering code.

See Also:



1189
# File 'rdoc/gosu.rb', line 1189

def clip_to(x, y, w, h); end

.clipboardString

Returns the contents of the clipboard as plain text, or an empty string if none is available.

Returns:

  • (String)


1050
# File 'rdoc/gosu.rb', line 1050

def clipboard(); end

.clipboard=(text) ⇒ nil

Replaces the contents of the clipboard with the given string.

Returns:

  • (nil)


1056
# File 'rdoc/gosu.rb', line 1056

def clipboard=(text); end

.default_font_nameString

Returns the name of a neutral font that is available on the current platform.

Returns:

  • (String)

    the name of a neutral font that is available on the current platform.

See Also:



1379
# File 'rdoc/gosu.rb', line 1379

def default_font_name(); end

.distance(x1, y1, x2, y2) ⇒ Float

Returns the distance from (x1, y1) to (x2, y2).

Parameters:

  • x1 (Float)
  • y1 (Float)
  • x2 (Float)
  • y2 (Float)

Returns:

  • (Float)

    the distance from (x1, y1) to (x2, y2).



1363
# File 'rdoc/gosu.rb', line 1363

def distance(x1, y1, x2, y2); end

.draw_line(x1, y1, c1, x2, y2, c2, z = 0, mode = :default) ⇒ void

Note:

OpenGL lines are not reliable at all and may have a missing pixel at the start or end point. Relying on your machine’s behavior can only end in tears. Recommended for debugging purposes only.

This method returns an undefined value.

Draws a line from one point to another—inconsistently.

Parameters:

  • x1 (Float)

    the X coordinate of the start point.

  • y1 (Float)

    the Y coordinate of the start point.

  • c1 (Gosu::Color)

    the color of the start point.

  • x2 (Float)

    the X coordinate of the end point.

  • y2 (Float)

    the Y coordinate of the end point.

  • c2 (Gosu::Color)

    the color of the end point.

  • z (Float) (defaults to: 0)

    the Z-order.

  • mode (:default, :additive) (defaults to: :default)

    the blending mode to use.

See Also:



1080
# File 'rdoc/gosu.rb', line 1080

def draw_line(x1, y1, c1, x2, y2, c2, z=0, mode=:default); end

.draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z = 0, mode = :default) ⇒ void

This method returns an undefined value.

Draws a quad (actually two triangles).

Parameters:

  • x1 (Float)

    the X coordinate of the first vertex.

  • y1 (Float)

    the Y coordinate of the first vertex.

  • c1 (Gosu::Color)

    the color of the first vertex.

  • x2 (Float)

    the X coordinate of the second vertex.

  • y2 (Float)

    the Y coordinate of the second vertex.

  • c2 (Gosu::Color)

    the color of the second vertex.

  • x3 (Float)

    the X coordinate of the third vertex.

  • y3 (Float)

    the Y coordinate of the third vertex.

  • c3 (Gosu::Color)

    the color of the third vertex.

  • x4 (Float)

    the X coordinate of the fourth vertex.

  • y4 (Float)

    the Y coordinate of the fourth vertex.

  • c4 (Gosu::Color)

    the color of the fourth vertex.

  • z (Float) (defaults to: 0)

    the Z-order.

  • mode (:default, :additive) (defaults to: :default)

    the blending mode to use.

See Also:



1150
# File 'rdoc/gosu.rb', line 1150

def draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z=0, mode=:default); end

.draw_rect(x, y, width, height, c, z = 0, mode = :default) ⇒ void

This method returns an undefined value.

Draws a rectangle (actually a quad, or two triangles).

Parameters:

  • x (Float)

    the X coordinate of the rectangle’s top left corner.

  • y (Float)

    the Y coordinate of the rectangle’s top left corner.

  • width (Float)

    the width of the rectangle.

  • height (Float)

    the height of the rectangle.

  • c (Gosu::Color)

    the color of the rectangle.

  • z (Float) (defaults to: 0)

    the Z-order.

  • mode (:default, :additive) (defaults to: :default)

    the blending mode to use.

See Also:



1123
# File 'rdoc/gosu.rb', line 1123

def draw_rect(x, y, width, height, c, z=0, mode=:default); end

.draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z = 0, mode = :default) ⇒ void

This method returns an undefined value.

Draws a triangle.

Parameters:

  • x1 (Float)

    the X coordinate of the first vertex.

  • y1 (Float)

    the Y coordinate of the first vertex.

  • c1 (Gosu::Color)

    the color of the first vertex.

  • x2 (Float)

    the X coordinate of the second vertex.

  • y2 (Float)

    the Y coordinate of the second vertex.

  • c2 (Gosu::Color)

    the color of the second vertex.

  • x3 (Float)

    the X coordinate of the third vertex.

  • y3 (Float)

    the Y coordinate of the third vertex.

  • c3 (Gosu::Color)

    the color of the third vertex.

  • z (Float) (defaults to: 0)

    the Z-order.

  • mode (:default, :additive) (defaults to: :default)

    the blending mode to use.

See Also:



1103
# File 'rdoc/gosu.rb', line 1103

def draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default); end

.flushvoid

This method returns an undefined value.

Flushes all drawing operations to OpenGL so that Z-ordering can start anew. This is useful for drawing multiple layers that may not have knowledge of each other’s Z-ordering, e.g., drawing a HUD on top of the game world or ensuring that a custom cursor is always drawn above everything else.



1159
# File 'rdoc/gosu.rb', line 1159

def flush; end

.fpsInteger

Returns the current framerate, in frames per second.

Returns:

  • (Integer)

    the current framerate, in frames per second.



1373
# File 'rdoc/gosu.rb', line 1373

def fps(); end

.gamepad_name(index) ⇒ String?

Returns the name for gamepad at ‘index` or nil if there is no connected at the specified index.

Examples:

Gosu.gamepad_name(0) #=> "PS4 Controller"

Parameters:

  • index (Integer)

Returns:

  • (String, nil)


1033
# File 'rdoc/gosu.rb', line 1033

def gamepad_name(index); end

.gl(z = nil) { ... } ⇒ void

Note:

Gosu does not provide access to the underlying OpenGL APIs. A gem like ruby-opengl is required to use custom OpenGL drawing code.

Note:

Gosu rendering functions MUST NOT be used within the block, and gl MUST be used only within the call tree of Gosu::Window#draw.

This method returns an undefined value.

Runs the block in a clean OpenGL environment.

If a Z-order is given, the block will be scheduled to run between Gosu drawing operations as normal; otherwise, all prior drawing operations will be flushed and the block will be executed immediately.

Parameters:

  • z (Float) (defaults to: nil)

    the Z-order.

Yields:

  • OpenGL code.

See Also:



1176
# File 'rdoc/gosu.rb', line 1176

def gl(z=nil); end

.languageString

Returns the language code for the user’s preferred language. Expect return values such as ‘en_US’, ‘de_DE.UTF-8’, ‘ja’, ‘zh-Hans’, etc. You can rely only the first two letters being a language abbreviation.

Returns:

  • (String)

    the user’s preferred language.



1405
# File 'rdoc/gosu.rb', line 1405

def language(); end

.millisecondsInteger

Note:

For long-running games, this counter will eventually wrap around to 0 again.

Returns the number of milliseconds elapsed.

Returns:

  • (Integer)

    the number of milliseconds elapsed.



1369
# File 'rdoc/gosu.rb', line 1369

def milliseconds(); end

.offset_x(theta, r) ⇒ Float

Returns the X component of a vector of angle theta and magnitude r, or the horizontal distance covered by moving r pixels in the direction given by theta.

Parameters:

  • theta (Float)
  • r (Float)

Returns:

  • (Float)

    the X component of a vector of angle theta and magnitude r, or the horizontal distance covered by moving r pixels in the direction given by theta.



1335
# File 'rdoc/gosu.rb', line 1335

def offset_x(theta, r); end

.offset_y(theta, r) ⇒ Float

Returns the Y component of a vector of angle theta and magnitude r, or the vertical distance covered by moving r pixels in the direction given by theta.

Parameters:

  • theta (Float)
  • r (Float)

Returns:

  • (Float)

    the Y component of a vector of angle theta and magnitude r, or the vertical distance covered by moving r pixels in the direction given by theta.



1341
# File 'rdoc/gosu.rb', line 1341

def offset_y(theta, r); end

.random(min, max) ⇒ Float

Returns a random number in the range [min; max).

Parameters:

  • min (Float)

    the minimum value, inclusive.

  • max (Float)

    the maximum value, exclusive.

Returns:

  • (Float)

    a random number in the range [min; max).



1329
# File 'rdoc/gosu.rb', line 1329

def random(min, max); end

.record(width, height) { ... } ⇒ Gosu::Image

Note:

Because the returned object is not backed by a bitmap texture, there are restrictions on how it can be used. For example, you can not use any color other than Gosu::Color#WHITE when drawing the image.

Note:

The width and height of the returned image will be the values you passed to record, regardless of the area you draw on.

Records all drawing operations inside the block as a macro (a special Image) that can be reused later on. This is useful for rendering larger groups of images (e.g. a tiled map in a game) and then rendering this group with a single call to Gosu::Image#draw.

It is important to pass accurate values if you plan on calling Gosu::Image#draw_as_quad or Gosu::Image#draw_rot on the result later.

Parameters:

  • width (Integer)

    the width of the recorded image.

  • height (Integer)

    the height of the recorded image.

Yields:

  • rendering code.

Returns:

See Also:



1207
# File 'rdoc/gosu.rb', line 1207

def record(width, height); end

.render(width, height) { ... } ⇒ Gosu::Image

Records all drawing operations inside the block and returns the result as a new Image.

Parameters:

  • width (Integer)

    the width of the recorded image.

  • height (Integer)

    the height of the recorded image.

  • options (Hash)

Yields:

  • rendering code.

Returns:

See Also:



1221
# File 'rdoc/gosu.rb', line 1221

def render(width, height); end

.rotate(angle, around_x = 0, around_y = 0) { ... } ⇒ void

This method returns an undefined value.

Rotates all drawing operations inside the block.

Parameters:

  • angle (Float)

    the rotation angle.

  • around_x (Float) (defaults to: 0)

    the X coordinate of the rotation origin.

  • around_y (Float) (defaults to: 0)

    the Y coordinate of the rotation origin.

Yields:

  • rendering code.

See Also:



1236
# File 'rdoc/gosu.rb', line 1236

def rotate(angle, around_x=0, around_y=0); end

.scale(scale_x, scale_y = scale_x) ⇒ void .scale(scale_x, scale_y, around_x, around_y) ⇒ void

This method returns an undefined value.

Scales all drawing operations inside the block.

Parameters:

  • scale_x (Float)

    the horizontal scaling factor.

  • scale_y (Float)

    the vertical scaling factor.

  • around_x (Float)

    the X coordinate of the scaling origin.

  • around_y (Float)

    the Y coordinate of the scaling origin.

Yields:

  • rendering code.

See Also:



1255
# File 'rdoc/gosu.rb', line 1255

def scale(scale_x, scale_y, around_x, around_y); end

.screen_height(window = nil) ⇒ Integer

Returns the height (in pixels) of a screen.

Parameters:

  • window (Gosu::Window) (defaults to: nil)

    The result describes the screen on which the window is shown, or the primary screen if no window is given.

Returns:

  • (Integer)

    the height (in pixels) of a screen.



1388
# File 'rdoc/gosu.rb', line 1388

def screen_height(window = nil); end

.screen_width(window = nil) ⇒ Integer

Returns the width (in pixels) of a screen.

Parameters:

  • window (Gosu::Window) (defaults to: nil)

    The result describes the screen on which the window is shown, or the primary screen if no window is given.

Returns:

  • (Integer)

    the width (in pixels) of a screen.



1384
# File 'rdoc/gosu.rb', line 1384

def screen_width(window = nil); end

.transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) { ... } ⇒ void

This method returns an undefined value.

Applies a free-form matrix transformation to everything drawn in the block.

Parameters:

  • m0 (Float)
  • m1 (Float)
  • m2 (Float)
  • m3 (Float)
  • m4 (Float)
  • m5 (Float)
  • m6 (Float)
  • m7 (Float)
  • m8 (Float)
  • m9 (Float)
  • m10 (Float)
  • m11 (Float)
  • m12 (Float)
  • m13 (Float)
  • m14 (Float)
  • m15 (Float)

Yields:

  • rendering code.

See Also:



1297
# File 'rdoc/gosu.rb', line 1297

def transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15); end

.translate(x, y) { ... } ⇒ void

This method returns an undefined value.

Offsets all drawing operations inside the block.

Parameters:

  • x (Float)

    the X offset.

  • y (Float)

    the Y offset.

Yields:

  • rendering code.

See Also:



1269
# File 'rdoc/gosu.rb', line 1269

def translate(x, y); end