Class: Metro::FadeTransitionScene

Inherits:
TransitionScene show all
Defined in:
lib/metro/transitions/fade_transition_scene.rb

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from TransitionScene

#next_scene, #options, #previous_scene

Attributes inherited from Scene

#window

Instance Method Summary collapse

Methods inherited from TransitionScene

#prepare_transition_from, #prepare_transition_to

Methods inherited from Scene

#_prepare_transition, #actor, #add_actors_to_scene, #after, after, #after_initialize, after_intervals, #base_draw, #base_update, #draw, #drawers, #enqueue, hierarchy, inherited, #initialize, metro_name, #notification, #prepare_transition_from, #prepare_transition_to, #register_actor, #register_actors!, #register_after_intervals!, #register_animations!, #register_events!, #register_events_for_target, scene_name, #scene_name, scenes, #state, #to_hash, #to_s, #transition_to, #update, #updaters

Methods included from SceneView

included, #save_view, #view, #view_content, #view_name

Methods included from HasAnimations

#animate, included

Methods included from HasEvents

included

Methods included from Draws

included

Constructor Details

This class inherits a constructor from Metro::Scene

Instance Method Details

#color_from_options(position) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/metro/transitions/fade_transition_scene.rb', line 57

def color_from_options(position)
  if options[position]
    if options[position][:color]
      Gosu::Color.new options[position][:color]
    end
  end
end

#default_final_colorObject



53
54
55
# File 'lib/metro/transitions/fade_transition_scene.rb', line 53

def default_final_color
  Gosu::Color.new "rgb(0,0,0)"
end

#default_intervalObject



29
30
31
# File 'lib/metro/transitions/fade_transition_scene.rb', line 29

def default_interval
  60
end

#default_starting_colorObject



41
42
43
# File 'lib/metro/transitions/fade_transition_scene.rb', line 41

def default_starting_color
  Gosu::Color.new "rgb(255,255,255)"
end

#final_colorObject



45
46
47
# File 'lib/metro/transitions/fade_transition_scene.rb', line 45

def final_color
  options_final_color || default_final_color
end

#intervalObject



25
26
27
# File 'lib/metro/transitions/fade_transition_scene.rb', line 25

def interval
  options[:interval] || default_interval
end

#options_final_colorObject



49
50
51
# File 'lib/metro/transitions/fade_transition_scene.rb', line 49

def options_final_color
  color_from_options(:to)
end

#options_starting_colorObject



37
38
39
# File 'lib/metro/transitions/fade_transition_scene.rb', line 37

def options_starting_color
  color_from_options(:from)
end

#showObject

When the scene is shown set up the starting color for the rectangle and queue the animation to transition the color to the final color.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/metro/transitions/fade_transition_scene.rb', line 10

def show
  rectangle.color = starting_color

  color = final_color

  animate :rectangle, to: { red: color.red,
                            green: color.green,
                            blue: color.blue,
                            alpha: color.alpha },
                      interval: interval do

    transition_to next_scene
  end
end

#starting_colorObject



33
34
35
# File 'lib/metro/transitions/fade_transition_scene.rb', line 33

def starting_color
  options_starting_color || default_starting_color
end