Class | Rubygame::Rect |
In: |
lib/rubygame/rect.rb
lib/rubygame/rect.rb |
Parent: | Array |
A Rect is a representation of a rectangle, with four core attributes (x offset, y offset, width, and height) and a variety of functions for manipulating and accessing these attributes.
Like all coordinates in Rubygame (and its base library, SDL), x and y offsets are measured from the top-left corner of the screen, with greater y offsets being lower. Thus, specifying the x and y offsets of the Rect is equivalent to setting the location of its top-left corner.
In Rubygame, Rects are used for collision detection and describing the area of a Surface to operate on.
Create a new Rect, attempting to extract its own information from the given arguments. The arguments must fall into one of these cases:
- 4 integers +(x, y, w, h)+. - 1 Rect or Array containing 4 integers +([x, y, w, h])+. - 2 Arrays containing 2 integers each +([x,y], [w,h])+. - 1 object with a +rect+ attribute which is a valid Rect object.
Create a new Rect, attempting to extract its own information from the given arguments. The arguments must fall into one of these cases:
- 4 integers +(x, y, w, h)+. - 1 Rect or Array containing 4 integers +([x, y, w, h])+. - 2 Arrays containing 2 integers each +([x,y], [w,h])+. - 1 object with a +rect+ attribute which is a valid Rect object.
Extract or generate a Rect from the given object, if possible, using the following process:
1. If it's a Rect already, return a duplicate Rect. 2. Elsif it's an Array with at least 4 values, make a Rect from it. 3. Elsif it has a +rect+ attribute., perform (1) and (2) on that. 4. Otherwise, raise TypeError.
See also Surface#make_rect()
Extract or generate a Rect from the given object, if possible, using the following process:
1. If it's a Rect already, return a duplicate Rect. 2. Elsif it's an Array with at least 4 values, make a Rect from it. 3. Elsif it has a +rect+ attribute., perform (1) and (2) on that. 4. Otherwise, raise TypeError.
See also Surface#make_rect()
Iterate through all elements in the given Array, and return the index of the first element which is a Rect that collides with the caller.
Iterate through all elements in the given Array, and return the index of the first element which is a Rect that collides with the caller.
Iterate through all elements in the given Array, and return an Array containing the indices of every element that is a Rect that collides with the caller.
Iterate through all elements in the given Array, and return an Array containing the indices of every element that is a Rect that collides with the caller.
Iterate through all key/value pairs in the given hash table, and return an Array of every pair whose value is a Rect that collides the caller.
Because a hash table is unordered, you should not expect the returned pairs to be in any particular order.
Iterate through all key/value pairs in the given hash table, and return an Array of every pair whose value is a Rect that collides the caller.
Because a hash table is unordered, you should not expect the returned pairs to be in any particular order.
True if the point is inside (including on the border) of the caller. If you have Array of coordinates, you can use collide_point?(*coords).
True if the point is inside (including on the border) of the caller. If you have Array of coordinates, you can use collide_point?(*coords).