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
-
.draw_line(x1, y1, c1, x2, y2, c2, z = 0, mode = :default) ⇒ void
Draws a line from one point to another—inconsistently.
-
.draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z = 0, mode = :default) ⇒ void
Draws a quad (actually two triangles).
-
.draw_rect(x, y, width, height, c, z = 0, mode = :default) ⇒ void
Draws a rectangle (actually a quad, or two triangles).
-
.draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z = 0, mode = :default) ⇒ void
Draws a triangle.
Manipulating the current drawing context collapse
-
.clip_to(x, y, w, h) { ... } ⇒ void
Masks the drawing area inside the block.
-
.flush ⇒ void
Flushes all drawing operations to OpenGL so that Z-ordering can start anew.
-
.gl(z = nil) { ... } ⇒ void
Runs the block in a clean OpenGL environment.
-
.record(width, height) { ... } ⇒ Gosu::Image
Records all drawing operations inside the block as a macro (a special Image) that can be reused later on.
-
.render(width, height) { ... } ⇒ Gosu::Image
Records all drawing operations inside the block and returns the result as a new Image.
-
.rotate(angle, around_x = 0, around_y = 0) { ... } ⇒ void
Rotates all drawing operations inside the block.
-
.scale(scale_x, scale_y, around_x, around_y) { ... } ⇒ void
Scales all drawing operations inside the block.
-
.transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15) { ... } ⇒ void
Applies a free-form matrix transformation to everything drawn in the block.
-
.translate(x, y) { ... } ⇒ void
Offsets all drawing operations inside the block.
Class Method Summary collapse
-
.angle(x1, y1, x2, y2) ⇒ Float
The angular distance from (x1, y1) to (x1, y2) in degrees, where 0.0 is up.
-
.angle_diff(angle1, angle2) ⇒ Float
The shortest angular distance from angle1 to angle2.
-
.available_height(window = nil) ⇒ Integer
All windows larger than this size will automatically be shrunk to fit.
-
.available_width(window = nil) ⇒ Integer
All windows larger than this size will automatically be shrunk to fit.
-
.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.
-
.button_down?(id) ⇒ true, false
Returns whether the button ‘id` is currently pressed.
-
.button_id_to_char(id) ⇒ String?
Returns the character a button usually produces, if any.
-
.button_name(id) ⇒ String?
Returns the name of a Gosu::KB_* constant.
-
.char_to_button_id(char) ⇒ Integer?
Returns the button that usually produces a character, if any.
-
.clipboard ⇒ String
Returns the contents of the clipboard as plain text, or an empty string if none is available.
-
.clipboard=(text) ⇒ nil
Replaces the contents of the clipboard with the given string.
-
.default_font_name ⇒ String
The name of a neutral font that is available on the current platform.
-
.distance(x1, y1, x2, y2) ⇒ Float
The distance from (x1, y1) to (x2, y2).
-
.fps ⇒ Integer
The current framerate, in frames per second.
-
.gamepad_name(index) ⇒ String?
Returns the name for gamepad at ‘index` or nil if there is no connected at the specified index.
-
.language ⇒ String
Returns the language code for the user’s preferred language.
-
.milliseconds ⇒ Integer
The number of milliseconds elapsed.
-
.offset_x(theta, r) ⇒ 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.
-
.offset_y(theta, r) ⇒ 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.
-
.random(min, max) ⇒ Float
A random number in the range [min; max).
-
.screen_height(window = nil) ⇒ Integer
The height (in pixels) of a screen.
-
.screen_width(window = nil) ⇒ Integer
The width (in pixels) of a screen.
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.
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.
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.
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.
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.
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.
1012 |
# File 'rdoc/gosu.rb', line 1012 def (id); end |
.button_id_to_char(id) ⇒ String?
For real text input, look at TextInput instead.
Returns the character a button usually produces, if any.
1312 |
# File 'rdoc/gosu.rb', line 1312 def (id); end |
.button_name(id) ⇒ String?
Returns the name of a Gosu::KB_* constant. Returns nil if no name is found.
1023 |
# File 'rdoc/gosu.rb', line 1023 def (id); end |
.char_to_button_id(char) ⇒ Integer?
Returns the button that usually produces a character, if any.
1323 |
# File 'rdoc/gosu.rb', line 1323 def (char); end |
.clip_to(x, y, w, h) { ... } ⇒ void
This method returns an undefined value.
Masks the drawing area inside the block.
1189 |
# File 'rdoc/gosu.rb', line 1189 def clip_to(x, y, w, h); end |
.clipboard ⇒ String
Returns the contents of the clipboard as plain text, or an empty string if none is available.
1050 |
# File 'rdoc/gosu.rb', line 1050 def clipboard(); end |
.clipboard=(text) ⇒ nil
Replaces the contents of the clipboard with the given string.
1056 |
# File 'rdoc/gosu.rb', line 1056 def clipboard=(text); end |
.default_font_name ⇒ String
Returns the name of a neutral font that is available on the current platform.
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).
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
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.
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).
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).
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.
1103 |
# File 'rdoc/gosu.rb', line 1103 def draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default); end |
.flush ⇒ void
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 |
.fps ⇒ Integer
Returns 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.
1033 |
# File 'rdoc/gosu.rb', line 1033 def gamepad_name(index); end |
.gl(z = nil) { ... } ⇒ void
Gosu does not provide access to the underlying OpenGL APIs. A gem like ruby-opengl is required to use custom OpenGL drawing code.
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.
1176 |
# File 'rdoc/gosu.rb', line 1176 def gl(z=nil); end |
.language ⇒ String
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.
1405 |
# File 'rdoc/gosu.rb', line 1405 def language(); end |
.milliseconds ⇒ Integer
For long-running games, this counter will eventually wrap around to 0 again.
Returns 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.
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.
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).
1329 |
# File 'rdoc/gosu.rb', line 1329 def random(min, max); end |
.record(width, height) { ... } ⇒ Gosu::Image
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.
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.
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.
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.
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.
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.
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.
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.
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.
1269 |
# File 'rdoc/gosu.rb', line 1269 def translate(x, y); end |