Class: Metro::ImplicitAnimation
- Inherits:
-
OnUpdateOperation
- Object
- OnUpdateOperation
- Metro::ImplicitAnimation
- Defined in:
- lib/metro/animation/implicit_animation.rb
Overview
The actor object must respond to setter methods that match the specified attributes (e.g. x, y).
An Implicit Animation is an animation without all the work. This little animation will take care of figuring out moving an actor from one position to another, the rotation, the alpha, etc.
Here an animation is created that will move the player to the position (final_x,final_y), specified in the :to hash that is provided, over the interval of 80 steps. Additionally the movement is done with an easing in.
The context provided is the context that the ‘on_complete’ block is executed. In this case, upon completition, transition the scene from the current one to the main scene.
Defined Under Namespace
Classes: AnimationStep
Instance Attribute Summary collapse
-
#easing ⇒ Object
readonly
The type of easing that the implicit animation should employ.
Attributes inherited from OnUpdateOperation
#complete_block, #current_step, #step_block
Instance Method Summary collapse
-
#after_initialize ⇒ Object
Additional initializion is required to calculate the attributes that are going to be animated and to determine each of their deltas.
- #animations ⇒ Object
- #build_animation_step(attribute, start, final) ⇒ Object
-
#delta_for_step(attribute) ⇒ Object
The delta for the attribute for the given step.
-
#easing_for(name) ⇒ Object
The correct easing based on the specified name.
-
#execute_step ⇒ Object
The ImplicitAnimation overrides the Animation#execute_step and updates the attributes of the actor based upon the value of the current animation step.
Methods inherited from OnUpdateOperation
#complete!, #completed?, #initialize, #next_step, #on_complete, #on_step, #step_interval, #update
Constructor Details
This class inherits a constructor from Metro::OnUpdateOperation
Instance Attribute Details
#easing ⇒ Object (readonly)
Returns the type of easing that the implicit animation should employ. By default it uses linear but can be overridden when the easing is configured.
46 47 48 |
# File 'lib/metro/animation/implicit_animation.rb', line 46 def easing @easing end |
Instance Method Details
#after_initialize ⇒ Object
Additional initializion is required to calculate the attributes that are going to be animated and to determine each of their deltas.
52 53 54 55 56 57 |
# File 'lib/metro/animation/implicit_animation.rb', line 52 def after_initialize to.each do |attribute,final| start = actor.send(attribute) animations.push build_animation_step(attribute,start,final) end end |
#animations ⇒ Object
37 38 39 |
# File 'lib/metro/animation/implicit_animation.rb', line 37 def animations @animations ||= [] end |
#build_animation_step(attribute, start, final) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/metro/animation/implicit_animation.rb', line 59 def build_animation_step(attribute,start,final) step = AnimationStep.new step.actor = actor step.attribute = attribute step.deltas = easing_for(easing).calculate(start.to_f,final.to_f,interval.to_f) step end |
#delta_for_step(attribute) ⇒ Object
Returns the delta for the attribute for the given step.
95 96 97 |
# File 'lib/metro/animation/implicit_animation.rb', line 95 def delta_for_step(attribute) deltas[attribute].at(current_step) end |
#easing_for(name) ⇒ Object
Returns the correct easing based on the specified name. When the name provided does not match anything then default to linear easing.
79 80 81 |
# File 'lib/metro/animation/implicit_animation.rb', line 79 def easing_for(name) Metro::Easing.easing_for(name) end |
#execute_step ⇒ Object
The ImplicitAnimation overrides the Animation#execute_step and updates the attributes of the actor based upon the value of the current animation step.
88 89 90 |
# File 'lib/metro/animation/implicit_animation.rb', line 88 def execute_step animations.each {|step| step.execute_step(current_step) } end |