Class | Rubygame::Sprites::Group |
In: |
lib/rubygame/sprite.rb
lib/rubygame/sprite.rb |
Parent: | Array |
The Group class is a special container, based on Array, with supplemental methods for handling multiple Sprite objects. Group can draw, update, and check collision for all its member sprites with one call.
All members of a Group must be unique (duplicates will be refused), and should be a Sprite (or functionally equivalent).
Check collision between each member of the calling Group and each member of group. Returns a Hash table with each member of the calling Group as a key, and as a value an Array of all members of group that it collided with.
If a block is given, that block is executed for every pair of colliding sprites. For example, if a1 collides with b1 and b2, the block will be called twice: once with [ a1, b1 ] and once with [ a1, b2 ].
Example:
# 'kills' both sprites when they collide groupA,collide_group(groupB) do |a, b| a.kill b.kill end
NOTE: killa and killb are deprecated and will be removed in the future. It is highly recommended that you use the block argument instead.
IMPORTANT: killa and killb will be ignored if a block is given!
If killa is true and a sprite in group A collides with a sprite in group B, the sprite in group A will have its kill method called; the same goes for killb and group B.
Check collision between each member of the calling Group and each member of group. Returns a Hash table with each member of the calling Group as a key, and as a value an Array of all members of group that it collided with.
If a block is given, that block is executed for every pair of colliding sprites. For example, if a1 collides with b1 and b2, the block will be called twice: once with [ a1, b1 ] and once with [ a1, b2 ].
Example:
# 'kills' both sprites when they collide groupA,collide_group(groupB) do |a, b| a.kill b.kill end
NOTE: killa and killb are deprecated and will be removed in the future. It is highly recommended that you use the block argument instead.
IMPORTANT: killa and killb will be ignored if a block is given!
If killa is true and a sprite in group A collides with a sprite in group B, the sprite in group A will have its kill method called; the same goes for killb and group B.
Check collision between each member of the Group and sprite. Returns an Array of all member sprites that collided with sprite. If none collided, returns an empty Array.
Check collision between each member of the Group and sprite. Returns an Array of all member sprites that collided with sprite. If none collided, returns an empty Array.
Draw every sprite on Surface dest. Calls Sprite#draw for every member sprite, passing dest as the argument. See also call and update.
Draw every sprite on Surface dest. Calls Sprite#draw for every member sprite, passing dest as the argument. See also call and update.
Update every member sprite. Calls Sprite#update for every member sprite, passing on all arguments. See also call and draw.
Update every member sprite. Calls Sprite#update for every member sprite, passing on all arguments. See also call and draw.