Module Rubygame::Sprites::LimitGroup
In: lib/rubygame/sprite.rb
lib/rubygame/sprite.rb

LimitGroup is a mix-in module that extends Group to limit the number of sprites it can contain. If the limit has been reached, each new sprite will "push out" the oldest sprite, on a First-In-First-Out basis.

The limit can be set either when the LimitGroup is created, or at any time during execution. However, if you reduce the limit, excess sprites will not be removed until the next time a sprite is added. (You can work around this by pushing the last sprite in the group again; the duplicate will be removed.)

Please note that, because Group#push is defined in terms of Group#<<, both LimitGroup#<< and LimitGroup#push work properly, even though only LimitGroup#<< is defined.

Methods

<<   <<   extend_object   extend_object   new   new  

Attributes

limit  [RW] 
limit  [RW] 

Public Class methods

Defines and sets @limit = 1 when an existing object is extended.

Defines and sets @limit = 1 when an existing object is extended.

Initialize the LimitGroup and define @limit (as 1, by default).

Initialize the LimitGroup and define @limit (as 1, by default).

Public Instance methods

Add sprite to the LimitGroup, removing the oldest member if necessary to keep under the limit. If sprite is already in the LimitGroup, it will be moved to the top of the queue.

Add sprite to the LimitGroup, removing the oldest member if necessary to keep under the limit. If sprite is already in the LimitGroup, it will be moved to the top of the queue.

[Validate]