Class: Darkholme::IteratingSystem
- Defined in:
- lib/darkholme/iterating_system.rb
Overview
A subclass of System, IteratingSystem automatically loops through entities belonging to it and calls #process on them, along with a before and after callback
Instance Attribute Summary
Attributes inherited from System
Instance Method Summary collapse
-
#after_processing ⇒ Object
Called once a frame after the entities are looped over and processed.
-
#before_processing ⇒ Object
Called once a frame before the entities are looped over and processed.
-
#process(entity, delta) ⇒ Object
Called on each entity in the collection.
-
#update(delta) ⇒ Object
Called by the engine, this calls #before_processing, then #process on each entity, then #after_processing.
Methods inherited from System
#added_to_engine, #entities, #family, has_family, #removed_from_engine
Instance Method Details
#after_processing ⇒ Object
Called once a frame after the entities are looped over and processed
37 38 |
# File 'lib/darkholme/iterating_system.rb', line 37 def after_processing end |
#before_processing ⇒ Object
Called once a frame before the entities are looped over and processed
33 34 |
# File 'lib/darkholme/iterating_system.rb', line 33 def before_processing end |
#process(entity, delta) ⇒ Object
Called on each entity in the collection. This where the various components’ data will be manipulated. This must be overridden by the subclass.
28 29 30 |
# File 'lib/darkholme/iterating_system.rb', line 28 def process(entity, delta) raise NotImplementedError.new("You must override #process(entity, delta)") end |
#update(delta) ⇒ Object
Called by the engine, this calls #before_processing, then #process on each entity, then #after_processing
13 14 15 16 17 18 19 |
# File 'lib/darkholme/iterating_system.rb', line 13 def update(delta) before_processing entities.each do |entity| process(entity, delta) end after_processing end |