### Home Classes Methods

### In Files

- lib/rubygame/sprite.rb

### Parent

Array

### Methods

- #<<
- #call
- #clear
- #collide_group
- #collide_sprite
- #delete
- #draw
- #push
- #update

### Files

- CREDITS
- LICENSE
- NEWS
- README
- ROADMAP
- custom_sdl_load_paths.rdoc
- getting_started.rdoc
- keyboard_symbols.rdoc
- macosx_install.rdoc
- managing_framerate.rdoc
- surface_palettes.rdoc
- windows_install.rdoc

### Class/Module Index

Quicksearch

- Rubygame
- Rubygame::ActiveEvent
- Rubygame::Clock
- Rubygame::Color
- Rubygame::Color::ColorBase
- Rubygame::Color::ColorHSL
- Rubygame::Color::ColorHSV
- Rubygame::Color::ColorRGB
- Rubygame::Color::Palette
- Rubygame::Event
- Rubygame::EventActions
- Rubygame::EventActions::BlockAction
- Rubygame::EventActions::MethodAction
- Rubygame::EventActions::MultiAction
- Rubygame::EventHandler
- Rubygame::EventHandler::HasEventHandler
- Rubygame::EventHook
- Rubygame::EventQueue
- Rubygame::EventTriggers
- Rubygame::EventTriggers::AndTrigger
- Rubygame::EventTriggers::AttrTrigger
- Rubygame::EventTriggers::BlockTrigger
- Rubygame::EventTriggers::InstanceOfTrigger
- Rubygame::EventTriggers::KeyPressTrigger
- Rubygame::EventTriggers::KeyReleaseTrigger
- Rubygame::EventTriggers::KindOfTrigger
- Rubygame::EventTriggers::MouseMoveTrigger
- Rubygame::EventTriggers::MousePressTrigger
- Rubygame::EventTriggers::MouseReleaseTrigger
- Rubygame::EventTriggers::OrTrigger
- Rubygame::EventTriggers::TickTrigger
- Rubygame::EventTriggers::YesTrigger
- Rubygame::Events
- Rubygame::Events::ClockTicked
- Rubygame::Events::InputFocusGained
- Rubygame::Events::InputFocusLost
- Rubygame::Events::JoystickAxisMoved
- Rubygame::Events::JoystickBallMoved
- Rubygame::Events::JoystickButtonEvent
- Rubygame::Events::JoystickButtonPressed
- Rubygame::Events::JoystickButtonReleased
- Rubygame::Events::JoystickHatMoved
- Rubygame::Events::KeyPressed
- Rubygame::Events::KeyReleased
- Rubygame::Events::KeyboardEvent
- Rubygame::Events::MouseButtonEvent
- Rubygame::Events::MouseFocusGained
- Rubygame::Events::MouseFocusLost
- Rubygame::Events::MouseMoved
- Rubygame::Events::MousePressed
- Rubygame::Events::MouseReleased
- Rubygame::Events::QuitRequested
- Rubygame::Events::WindowExposed
- Rubygame::Events::WindowMinimized
- Rubygame::Events::WindowResized
- Rubygame::Events::WindowUnminimized
- Rubygame::ExposeEvent
- Rubygame::Ftor
- Rubygame::GL
- Rubygame::Hotspot
- Rubygame::JoyAxisEvent
- Rubygame::JoyBallEvent
- Rubygame::JoyDownEvent
- Rubygame::JoyHatEvent
- Rubygame::JoyUpEvent
- Rubygame::Joystick
- Rubygame::Key
- Rubygame::KeyDownEvent
- Rubygame::KeyUpEvent
- Rubygame::MailQueue
- Rubygame::MediaBag
- Rubygame::Mixer
- Rubygame::Mixer::Music
- Rubygame::Mixer::Sample
- Rubygame::Mouse
- Rubygame::MouseDownEvent
- Rubygame::MouseMotionEvent
- Rubygame::MouseUpEvent
- Rubygame::Music
- Rubygame::NamedResource
- Rubygame::NamedResource::NamedResourceClassMethods
- Rubygame::QuitEvent
- Rubygame::Rect
- Rubygame::ResizeEvent
- Rubygame::SDLError
- Rubygame::SFont
- Rubygame::Screen
- Rubygame::Sound
- Rubygame::Sprites
- Rubygame::Sprites::DepthSortGroup
- Rubygame::Sprites::Group
- Rubygame::Sprites::LimitGroup
- Rubygame::Sprites::Sprite
- Rubygame::Sprites::UpdateGroup
- Rubygame::Surface
- Rubygame::TTF

No matching classes.

# Rubygame::Sprites::Group

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

### Public Instance Methods

<<(sprite) click to toggle source

Add `sprite` to the Group. `sprite` is notified so that it can add this Group to its list of parent Groups. See also push.

    # File lib/rubygame/sprite.rb, line 240
    def <<(sprite)
            unless self.include? sprite
                    super(sprite)
                    sprite.add(self)
            end
            return self
    end

call(symbol,*args) click to toggle source

Call the method represented by `symbol` for every member sprite, giving `args` as the arguments to the method. This method uses Object#send, which does not hesitate to call private methods, so use this wisely! See also draw and update.

    # File lib/rubygame/sprite.rb, line 252
    def call(symbol,*args)
            self.each { |sprite|
                    sprite.send(symbol,*args)
            }
    end

clear() click to toggle source

Remove every member sprite from the Group. Each sprite is notified so that it can remove this Group from its list of parent Groups. See also delete.

    # File lib/rubygame/sprite.rb, line 261
    def clear
            self.dup.each { |sprite| sprite.remove(self) }
    end

collide_group(group, &block) → Hash click to toggle source
collide_group(group, killa=false, killb=false) → Hash # deprecated

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.

    # File lib/rubygame/sprite.rb, line 305
    def collide_group(group, killa=false, killb=false, &block)
            sprites = {}
            self.each { |sprite|
                    col = sprite.collide_group(group)
                    sprites[sprite] = col if col.length > 0
            }

            if block_given?
                    sprites.each_pair do |a, bs|
                            bs.each { |b| yield(a, b) }
                    end
            else
                    # killa and killb only work if no block is given
                    if killa
                            sprites.each_key { |sprite| sprite.kill }
                    end
                    if killb
                            sprites.each_value do |array|
                                    array.each { |sprite| sprite.kill }
                            end
                    end
            end

            return sprites
    end

collide_sprite(sprite) → Array click to toggle source

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.

    # File lib/rubygame/sprite.rb, line 270
    def collide_sprite(sprite)
            sprite.collide_group(self)
    end

delete(*sprites) click to toggle source

Remove each sprite in `sprites` from the Group. Each sprite is notified so that it can remove this Group from its list of parent Groups. Note that this will not work correctly if fed a list of its own sprites (use Array.dup if you want correct behavior)

    # File lib/rubygame/sprite.rb, line 335
    def delete(*sprites)
            sprites.each { |sprite|
                    if self.include? sprite
                            super(sprite)
                            sprite.remove(self)
                    end
            }
            return self
    end

draw(dest) click to toggle source

Draw every sprite on Surface `dest`. Calls Sprite#draw for every member sprite, passing `dest` as the argument. See also call and update.

    # File lib/rubygame/sprite.rb, line 347
    def draw(dest)
            self.each { |sprite| sprite.draw(dest) }
    end

push(*sprites) click to toggle source

Add each sprite in `sprites` to the Group. Each sprite is notified so that it can add this Group to its list of parent Groups. See also #<<.

    # File lib/rubygame/sprite.rb, line 353
    def push(*sprites)
            sprites.each { |sprite|
                    self << sprite
            }
            return self
    end

update(*args) click to toggle source

Update every member sprite. Calls Sprite#update for every member sprite, passing on all arguments. See also call and draw.

    # File lib/rubygame/sprite.rb, line 362
    def update(*args)
            self.each { |sprite|
                    sprite.update(*args)
            }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.