Class: Reight::Map::SpriteArray
- Inherits:
-
Array
- Object
- Array
- Reight::Map::SpriteArray
- Defined in:
- lib/reight/map.rb
Instance Attribute Summary collapse
-
#world ⇒ Object
readonly
Returns the value of attribute world.
Instance Method Summary collapse
- #activate(x, y, w, h, &activated) ⇒ Object
- #delete(sprite) ⇒ Object
- #drawSprite__(context) ⇒ Object
-
#initialize(world: nil, sprites: [], &each_chunk) ⇒ SpriteArray
constructor
A new instance of SpriteArray.
- #inspect ⇒ Object
Constructor Details
#initialize(world: nil, sprites: [], &each_chunk) ⇒ SpriteArray
Returns a new instance of SpriteArray.
350 351 352 353 |
# File 'lib/reight/map.rb', line 350 def initialize(world: nil, sprites: [], &each_chunk) @world, @each_chunk = world, each_chunk super(sprites) end |
Instance Attribute Details
#world ⇒ Object (readonly)
Returns the value of attribute world.
355 356 357 |
# File 'lib/reight/map.rb', line 355 def world @world end |
Instance Method Details
#activate(x, y, w, h, &activated) ⇒ Object
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/reight/map.rb', line 357 def activate(x, y, w, h, &activated) raise ArgumentError, "missing 'activated' block" if !@world && !activated bounds, old_bounds = [x, y, w, h], @bounds return if bounds == old_bounds chunks, old_chunks = @each_chunk.call(x, y, w, h).to_a, @chunks || [] return if chunks == old_chunks activateds, deactivateds = [chunks - old_chunks, old_chunks - chunks] .map {|chunks| chunks.map(&:sprites).flatten.compact} if activated activated.call activateds, deactivateds elsif @world activateds.each {@world .add_sprite _1} deactivateds.each {@world.remove_sprite _1} end @bounds, @chunks = bounds, chunks clear.concat @chunks.map(&:sprites).flatten.compact end |
#delete(sprite) ⇒ Object
379 380 381 382 |
# File 'lib/reight/map.rb', line 379 def delete(sprite) sprite.map_chunk&.delete_sprite__ sprite super end |
#drawSprite__(context) ⇒ Object
388 389 390 |
# File 'lib/reight/map.rb', line 388 def drawSprite__(context) (@chunks&.each || each).each {_1.drawSprite__ context} end |
#inspect ⇒ Object
384 385 386 |
# File 'lib/reight/map.rb', line 384 def inspect() "#<#{self.class.name}:0x#{object_id}>" end |