### Home Classes Methods

### In Files

- lib/rubygame/sprite.rb

### Methods

- ::extend_object
- ::new
- #draw
- #undraw

### 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::UpdateGroup

UpdateGroup is a mix-in module that extends Group to allow it to "erase" (i.e. draw over with a background Surface) and re-draw each sprite in its new position. This eliminates the "trail" of images that sprites would otherwise leave as they move around.

UpdateGroup adds a new attribute, @dirty_rects, which is an Array storing all Rects which need to be updated, including the old positions of the sprites. This attribute is returned when UpdateGroup#draw is called, so that it can be used to update the parts of the Screen that have changed.

The general order of calls each frame should be:

1. undraw; clear the old positions of the sprites.

2. update; update the sprites to their new positions.

3. draw; draw the sprites in their new positions.

This module can extend either a class or an already-existing Group instance (either empty or with members) without any special preparation.

### Attributes

dirty_rects[RW]

### Public Class Methods

extend_object(obj) click to toggle source

Defines @dirty_rects when an existing object is extended.

    # File lib/rubygame/sprite.rb, line 392
    def UpdateGroup.extend_object(obj)
            super
            obj.dirty_rects = []
    end

new() click to toggle source

Initialize the Group, calling `super` and defining @dirty_rects.

    # File lib/rubygame/sprite.rb, line 398
    def initialize
            super
            @dirty_rects = []
    end

### Public Instance Methods

draw(dest) → Array click to toggle source

Draw every sprite on Surface `dest`. See Group#draw. Returns an Array of Rects representing the portions of `dest` which were affected by the last undraw and this draw.

    # File lib/rubygame/sprite.rb, line 408
    def draw(dest)
            self.each { |sprite|
                    @dirty_rects.push( sprite.draw(dest) )
            }
            rects = @dirty_rects
            @dirty_rects = []
            return rects
    end

undraw(dest,background) click to toggle source

Draw over part of `dest` with image data from the corresponding part of `background`. For best results, `background` should be at least as big as `dest` (or, rather, the part of `dest` that will ever be drawn over).

    # File lib/rubygame/sprite.rb, line 421
    def undraw(dest,background)
            self.each { |sprite|
                    @dirty_rects.push( sprite.undraw(dest, background) )
            }
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.