Class: Gosu::Window

Inherits:
Object
  • Object
show all
Defined in:
reference/gosu.rb

Overview

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.

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Window) initialize(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.



526
# File 'reference/gosu.rb', line 526

def initialize(width, height, fullscreen, update_interval=16.666666) end

Instance Attribute Details

- (Object) caption

Returns the value of attribute caption



515
516
517
# File 'reference/gosu.rb', line 515

def caption
  @caption
end

- (Object) fullscreen? (readonly)

Returns the value of attribute fullscreen?



520
521
522
# File 'reference/gosu.rb', line 520

def fullscreen?
  @fullscreen?
end

- (Object) height (readonly)

Returns the value of attribute height



519
520
521
# File 'reference/gosu.rb', line 519

def height
  @height
end

- (Object) mouse_x

Returns the value of attribute mouse_x



516
517
518
# File 'reference/gosu.rb', line 516

def mouse_x
  @mouse_x
end

- (Object) mouse_y

Returns the value of attribute mouse_y



517
518
519
# File 'reference/gosu.rb', line 517

def mouse_y
  @mouse_y
end

- (Object) text_input

Returns the value of attribute text_input



518
519
520
# File 'reference/gosu.rb', line 518

def text_input
  @text_input
end

- (Object) update_interval (readonly)

Returns the value of attribute update_interval



521
522
523
# File 'reference/gosu.rb', line 521

def update_interval
  @update_interval
end

- (Object) width (readonly)

Returns the value of attribute width



519
520
521
# File 'reference/gosu.rb', line 519

def width
  @width
end

Class Method Details

+ (Object) button_id_to_char(id)

Returns the character a button usually produces, or nil. To implement real text-input facilities, look at the TextInput class instead.



624
# File 'reference/gosu.rb', line 624

def self.button_id_to_char(id) end

+ (Object) char_to_button_id(char)

Returns the button that has to be pressed to produce the given character, or nil.



627
# File 'reference/gosu.rb', line 627

def self.char_to_button_id(char) end

Instance Method Details

- (Object) button_down(id)

Called before update when the user pressed a button while the window had the focus.



557
# File 'reference/gosu.rb', line 557

def button_down(id) end

- (Boolean) button_down?(id)

Returns true if a button is currently pressed. Updated every tick.

Returns:

  • (Boolean)


562
# File 'reference/gosu.rb', line 562

def button_down?(id) end

- (Object) button_up(id)

Same as buttonDown. Called then the user released a button.



559
# File 'reference/gosu.rb', line 559

def button_up(id) end

- (Object) clip_to(x, y, w, h, &rendering_code)

Limits the drawing area to a given rectangle while evaluating the code inside of the block.



594
# File 'reference/gosu.rb', line 594

def clip_to(x, y, w, h, &rendering_code) end

- (Object) close

Tells the window to end the current show loop as soon as possible.



532
# File 'reference/gosu.rb', line 532

def close; end

- (Object) draw

Called after every update and when the OS wants the window to repaint itself. Your application’s rendering code goes here.



540
# File 'reference/gosu.rb', line 540

def draw; end

- (Object) draw_line(x1, y1, c1, x2, y2, c2, z = 0, mode = :default)

Draws a line from one point to another (last pixel exclusive). Note: OpenGL lines are not reliable at all and may have a missing pixel at the start or end point. Please only use this for debugging purposes. Otherwise, use a quad or image to simulate lines, or contribute a better draw_line to Gosu.



568
# File 'reference/gosu.rb', line 568

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

- (Object) 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.



575
# File 'reference/gosu.rb', line 575

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

- (Object) draw_triangle(x1, y1, c1, x2, y2, c2, x3, y3, c3, z = 0, mode = :default)



570
# File 'reference/gosu.rb', line 570

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

- (Object) 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.



580
# File 'reference/gosu.rb', line 580

def flush; end

- (Object) gl(z = nil, &custom_gl_code)

For custom OpenGL calls. Executes the given block in a clean OpenGL environment. Use the ruby-opengl gem to access OpenGL function (if you manage to get it to work). IF no z position is given, it will execute the given block immediately, otherwise, the code will be scheduled to be called between Gosu drawing operations.

Note: You cannot call Gosu rendering functions within this block, and you can only call the gl function in the call tree of Window#draw.

See examples/OpenGLIntegration.rb for an example.



591
# File 'reference/gosu.rb', line 591

def gl(z=nil, &custom_gl_code) end

- (Boolean) 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.

Returns:

  • (Boolean)


553
# File 'reference/gosu.rb', line 553

def needs_cursor?; end

- (Boolean) 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.)

Returns:

  • (Boolean)


548
# File 'reference/gosu.rb', line 548

def needs_redraw?; end

- (Gosu::Image) record(width, height, &rendering_code)

Returns a Gosu::Image that containes everything rendered within the given block. It can be used to optimize rendering of many static images, e.g. the map. There are still several restrictions that you will be informed about via exceptions.

The returned Gosu::Image will have the width and height you pass as arguments, regardless of how the area you draw on. It is important to pass accurate values if you plan on using Gosu::Image#draw_as_quad or Gosu::Image#draw_rot with the result later.

Returns:



605
# File 'reference/gosu.rb', line 605

def record(width, height, &rendering_code) end

- (Object) rotate(angle, around_x = 0, around_y = 0, &rendering_code)

Rotates everything drawn in the block around (around_x, around_y).



608
# File 'reference/gosu.rb', line 608

def rotate(angle, around_x=0, around_y=0, &rendering_code) end

- (Object) scale(factor_x, factor_y, around_x, around_y, &rendering_code)

Scales everything drawn in the block by a factor for each dimension.



611
# File 'reference/gosu.rb', line 611

def scale(factor_x, factor_y, around_x, around_y, &rendering_code) end

- (Object) set_mouse_position(x, y)

Deprecated.

Use Window#mouse_x= and Window#mouse_y= instead.



630
# File 'reference/gosu.rb', line 630

def set_mouse_position(x, y) end

- (Object) show

Enters a modal loop where the Window is visible on screen and receives calls to draw, update etc.



529
# File 'reference/gosu.rb', line 529

def show; end

- (Object) transform(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, &rendering_code)

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



620
# File 'reference/gosu.rb', line 620

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

- (Object) translate(x, y, &rendering_code)

Moves everything drawn in the block by an offset in each dimension.



617
# File 'reference/gosu.rb', line 617

def translate(x, y, &rendering_code) end

- (Object) update

Called every update_interval milliseconds while the window is being shown. Your application’s main game logic goes here.



536
# File 'reference/gosu.rb', line 536

def update; end