Module: Rubygame::Sprites::BoundedGroup
- Defined in:
- lib/xgame.rb
Overview
This is a mixin module for groups that keep their sprites in a particular region of the screen
Instance Attribute Summary collapse
-
#bounds ⇒ Object
Bounding box (of type Rubygame::Rect).
Instance Method Summary collapse
Instance Attribute Details
#bounds ⇒ Object
Bounding box (of type Rubygame::Rect)
169 170 171 |
# File 'lib/xgame.rb', line 169 def bounds @bounds end |
Instance Method Details
#update(*args) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/xgame.rb', line 174 def update(*args) super(*args) self.each { |sprite| if sprite.rect.top < bounds.top sprite.rect.top = bounds.top sprite.stop(:up) if sprite.respond_to?(:stop) end if sprite.rect.bottom > bounds.bottom sprite.rect.bottom = bounds.bottom sprite.stop(:down) if sprite.respond_to?(:stop) end if sprite.rect.left < bounds.left sprite.rect.left = bounds.left sprite.stop(:left) if sprite.respond_to?(:stop) end if sprite.rect.right > bounds.right sprite.rect.right = bounds.right sprite.stop(:right) if sprite.respond_to?(:stop) end } end |