Module | Rubygame::Sprites::UpdateGroup
In: | lib/rubygame/sprite.rb

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.

### Methods

draw extend_object new undraw

### Attributes

dirty_rects | [RW] |

### Public Class methods

extend_object(obj)

Defines @dirty_rects when an existing object is extended.

new()

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

### Public Instance methods

draw(dest) → Array

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.

undraw(dest,background)

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

[Validate]