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_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_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_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_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.
-
.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.
-
.char_to_button_id(char) ⇒ Integer?
Returns the button that usually produces a character, if any.
-
.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.
-
.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.
1221 |
# File 'rdoc/gosu.rb', line 1221 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.
1227 |
# File 'rdoc/gosu.rb', line 1227 def angle_diff(angle1, angle2); end |
.available_height(window = nil) ⇒ Integer
All windows larger than this size will automatically be shrunk to fit.
1269 |
# File 'rdoc/gosu.rb', line 1269 def available_height(window = nil); end |
.available_width(window = nil) ⇒ Integer
All windows larger than this size will automatically be shrunk to fit.
1265 |
# File 'rdoc/gosu.rb', line 1265 def available_width(window = nil); 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.
929 |
# File 'rdoc/gosu.rb', line 929 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.
1184 |
# File 'rdoc/gosu.rb', line 1184 def self.(id); end |
.char_to_button_id(char) ⇒ Integer?
Returns the button that usually produces a character, if any.
1195 |
# File 'rdoc/gosu.rb', line 1195 def self.(char); end |
.clip_to(x, y, w, h) { ... } ⇒ void
This method returns an undefined value.
Masks the drawing area inside the block.
1061 |
# File 'rdoc/gosu.rb', line 1061 def clip_to(x, y, w, h); end |
.default_font_name ⇒ String
Returns the name of a neutral font that is available on the current platform.
1251 |
# File 'rdoc/gosu.rb', line 1251 def default_font_name(); end |
.distance(x1, y1, x2, y2) ⇒ Float
Returns the distance from (x1, y1) to (x2, y2).
1235 |
# File 'rdoc/gosu.rb', line 1235 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.
952 |
# File 'rdoc/gosu.rb', line 952 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).
1022 |
# File 'rdoc/gosu.rb', line 1022 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).
995 |
# File 'rdoc/gosu.rb', line 995 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.
975 |
# File 'rdoc/gosu.rb', line 975 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.
1031 |
# File 'rdoc/gosu.rb', line 1031 def flush; end |
.fps ⇒ Integer
Returns the current framerate, in frames per second.
1245 |
# File 'rdoc/gosu.rb', line 1245 def fps(); 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.
1048 |
# File 'rdoc/gosu.rb', line 1048 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.
1277 |
# File 'rdoc/gosu.rb', line 1277 def language(); end |
.milliseconds ⇒ Integer
For long-running games, this counter will eventually wrap around to 0 again.
Returns the number of milliseconds elapsed.
1241 |
# File 'rdoc/gosu.rb', line 1241 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.
1207 |
# File 'rdoc/gosu.rb', line 1207 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.
1213 |
# File 'rdoc/gosu.rb', line 1213 def offset_y(theta, r); end |
.random(min, max) ⇒ Float
Returns a random number in the range [min; max).
1201 |
# File 'rdoc/gosu.rb', line 1201 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.
1079 |
# File 'rdoc/gosu.rb', line 1079 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.
1093 |
# File 'rdoc/gosu.rb', line 1093 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.
1108 |
# File 'rdoc/gosu.rb', line 1108 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.
1127 |
# File 'rdoc/gosu.rb', line 1127 def scale(scale_x, scale_y, around_x, around_y); end |
.screen_height(window = nil) ⇒ Integer
Returns the height (in pixels) of a screen.
1260 |
# File 'rdoc/gosu.rb', line 1260 def screen_height(window = nil); end |
.screen_width(window = nil) ⇒ Integer
Returns the width (in pixels) of a screen.
1256 |
# File 'rdoc/gosu.rb', line 1256 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.
1169 |
# File 'rdoc/gosu.rb', line 1169 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.
1141 |
# File 'rdoc/gosu.rb', line 1141 def translate(x, y); end |