Class: Metro::OnUpdateOperation
- Inherits:
-
Object
- Object
- Metro::OnUpdateOperation
- Defined in:
- lib/metro/animation/on_update_operation.rb
Overview
OnUpdateOperation is an object that executes on the update cycle of the game. This usually take the form of an animation or some operation that needs to execute with each update of the game.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#complete_block ⇒ Object
readonly
Returns the value of attribute complete_block.
-
#current_step ⇒ Object
readonly
The current step of the animation.
-
#step_block ⇒ Object
readonly
Returns the value of attribute step_block.
Instance Method Summary collapse
- #after_initialize ⇒ Object
-
#complete! ⇒ Object
Perform the action that happens when the animation is completed.
-
#execute_step ⇒ Object
Perform the action that happens with each step of the animation.
-
#initialize(options) ⇒ OnUpdateOperation
constructor
A new instance of OnUpdateOperation.
-
#next_step ⇒ Object
Move to the next step in the animation.
-
#on_complete(&block) ⇒ Object
Sets the action that happens when the animation is completed.
-
#on_step(&block) ⇒ Object
Sets the action that happens with each step of the animation.
-
#step_interval ⇒ Object
The interval at which the animation take place.
-
#update ⇒ Object
Perform a step of an animation, if it hasn’t already been completed.
-
#update_completed? ⇒ Boolean
True if the animation has completed all the actions, false if there are remaining actions.
Constructor Details
#initialize(options) ⇒ OnUpdateOperation
Returns a new instance of OnUpdateOperation.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/metro/animation/on_update_operation.rb', line 12 def initialize() @current_step = 0 .each do |key,value| send :instance_variable_set, "@#{key}".to_sym, value self.class.send :define_method, key do instance_variable_get("@#{key}") end end after_initialize end |
Instance Attribute Details
#complete_block ⇒ Object (readonly)
Returns the value of attribute complete_block.
55 56 57 |
# File 'lib/metro/animation/on_update_operation.rb', line 55 def complete_block @complete_block end |
#current_step ⇒ Object (readonly)
Returns the current step of the animation.
53 54 55 |
# File 'lib/metro/animation/on_update_operation.rb', line 53 def current_step @current_step end |
#step_block ⇒ Object (readonly)
Returns the value of attribute step_block.
55 56 57 |
# File 'lib/metro/animation/on_update_operation.rb', line 55 def step_block @step_block end |
Instance Method Details
#after_initialize ⇒ Object
10 |
# File 'lib/metro/animation/on_update_operation.rb', line 10 def after_initialize ; end |
#complete! ⇒ Object
Perform the action that happens when the animation is completed.
89 90 91 |
# File 'lib/metro/animation/on_update_operation.rb', line 89 def complete! context.instance_eval(&@complete_block) if complete_block and context end |
#execute_step ⇒ Object
Perform the action that happens with each step of the animation.
82 83 84 |
# File 'lib/metro/animation/on_update_operation.rb', line 82 def execute_step context.instance_eval(&@step_block) if step_block and context end |
#next_step ⇒ Object
Move to the next step in the animation.
60 61 62 |
# File 'lib/metro/animation/on_update_operation.rb', line 60 def next_step @current_step = current_step + step_interval end |
#on_complete(&block) ⇒ Object
Sets the action that happens when the animation is completed.
34 35 36 |
# File 'lib/metro/animation/on_update_operation.rb', line 34 def on_complete(&block) @complete_block = block end |
#on_step(&block) ⇒ Object
Sets the action that happens with each step of the animation.
27 28 29 |
# File 'lib/metro/animation/on_update_operation.rb', line 27 def on_step(&block) @step_block = block end |
#step_interval ⇒ Object
Returns the interval at which the animation take place.
67 68 69 |
# File 'lib/metro/animation/on_update_operation.rb', line 67 def step_interval 1 end |
#update ⇒ Object
Perform a step of an animation, if it hasn’t already been completed.
41 42 43 44 45 46 47 48 |
# File 'lib/metro/animation/on_update_operation.rb', line 41 def update return if update_completed? execute_step next_step complete! if update_completed? end |
#update_completed? ⇒ Boolean
Returns true if the animation has completed all the actions, false if there are remaining actions.
75 76 77 |
# File 'lib/metro/animation/on_update_operation.rb', line 75 def update_completed? current_step >= interval end |