Main class that serves as the foundation of a standard Gosu application. Manages initialization of all of Gosu‘s core components and provides timing functionality.
Note that all coordinates, even the mouse position, are in client coordinates relative to the window. This means that the mouse position can be negative or larger than the window size.
Note that you should really only use one instance of this class at the same time. This may or may not change later.
Right now, having two or more windows and loading samples or songs on both of them will result in an exception.
Attributes
| Name | Read/write? |
|---|---|
| caption | RW |
| fullscreen? | R |
| height | R |
| mouse_x | RW |
| mouse_y | RW |
| text_input | RW |
| update_interval | R |
| width | R |
Public Class Methods
button_id_to_char (id)
DEPRECATED: Returns the character a button usually produces, or nil. Please use TextInput instead.
# File reference/gosu.rb, line 441 def self.button_id_to_char(id); end
char_to_button_id (char)
DEPRECATED: Returns the button that has to be pressed to produce the given character, or nil. Please use TextInput instead.
# File reference/gosu.rb, line 445 def self.char_to_button_id(char); end
new (width, height, fullscreen, update_interval = 16.666666)
| update_interval: | Interval in milliseconds between two calls |
to the update member function. The default means the game will run at 60 FPS, which is ideal on standard 60 Hz TFT screens.
# File reference/gosu.rb, line 378 def initialize(width, height, fullscreen, update_interval = 16.666666); end
Public Instance Methods
button_down (id)
Called before update when the user pressed a button while the window had the focus.
# File reference/gosu.rb, line 418 def button_down(id); end
button_down? (id)
Returns true if a button is currently pressed. Updated every tick.
# File reference/gosu.rb, line 438 def button_down?(id); end
button_up (id)
Same as buttonDown. Called then the user released a button.
# File reference/gosu.rb, line 420 def button_up(id); end
clip_to (x, y, w, h, &drawing_code)
Limits the drawing area to a given rectangle while evaluating the code inside of the block.
# File reference/gosu.rb, line 451 def clip_to(x, y, w, h, &drawing_code); end
close ()
Tells the window to end the current show loop as soon as possible.
# File reference/gosu.rb, line 384 def close; end
draw ()
Called after every update and when the OS wants the window to repaint itself. Your application‘s rendering code goes here.
# File reference/gosu.rb, line 392 def draw; end
draw_line (x1, y1, c1, x2, y2, c2, z=0, mode=:default)
Draws a line from one point to another (last pixel exclusive).
# File reference/gosu.rb, line 423 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)
Draws a rectangle (two triangles) with given corners and corresponding colors. The points can be in clockwise order, or in a Z shape.
# File reference/gosu.rb, line 430 def draw_quad(x1, y1, c1, x2, y2, c2, x3, y3, c3, x4, y4, c4, z=0, mode=:default); end
draw_triangle (x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default)
# File reference/gosu.rb, line 425 def draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z=0, mode=:default); end
flush ()
Flushes all drawing operations to OpenGL so that Z-ordering can start anew. This is useful when drawing several parts of code on top of each other that use conflicting z positions.
# File reference/gosu.rb, line 435 def flush; end
gl (&custom_gl_code)
See examples/OpenGLIntegration.rb.
# File reference/gosu.rb, line 448 def gl(&custom_gl_code); end
needs_cursor? ()
Can be overriden to show the system cursor when necessary, e.g. in level editors or other situations where introducing a custom cursor is not desired.
NOTE: Because of the way SWIG translates this between C++ and Ruby, you must return either true or false, not e.g. nil.
# File reference/gosu.rb, line 411 def needs_cursor?; end
needs_redraw? ()
Can be overriden to give the game a chance to say no to being redrawn. This is not a definitive answer. The operating system can still cause redraws for one reason or another.
By default, the window is redrawn all the time (i.e. Window#needs_redraw? always returns true.)
NOTE: Because of the way SWIG translates this between C++ and Ruby, you must return either true or false, not e.g. nil.
# File reference/gosu.rb, line 403 def needs_redraw?; end
rotate (angle, around_x = 0, around_y = 0 &drawing_code)
Rotates everything drawn in the block around (around_x, around_y).
# File reference/gosu.rb, line 454 def rotate(angle, around_x = 0, around_y = 0 &drawing_code); end
scale (factor_x, factor_y, &drawing_code)
Scales everything drawn in the block by a factor for each dimension.
# File reference/gosu.rb, line 460 def scale(factor_x, factor_y, &drawing_code); end
scale (factor, &drawing_code)
Scales everything drawn in the block by a factor.
# File reference/gosu.rb, line 457 def scale(factor, &drawing_code); end
set_mouse_position (x, y)
DEPRECATED.
# File reference/gosu.rb, line 414 def set_mouse_position(x, y); end
show ()
Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.
# File reference/gosu.rb, line 381 def show; end
transform (m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, &drawing_code)
Applies a free-form matrix rotation to everything drawn in the block.
# File reference/gosu.rb, line 466 def transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, &drawing_code); end
translate (x, y, &drawing_code)
Moves everything drawn in the block by an offset in each dimension.
# File reference/gosu.rb, line 463 def translate(x, y, &drawing_code); end
update ()
Called every update_interval milliseconds while the window is being shown. Your application‘s main game logic goes here.
# File reference/gosu.rb, line 388 def update; end