Class: Chingu::GameStates::FadeTo
- Inherits:
-
Chingu::GameState
- Object
- Chingu::GameState
- Chingu::GameStates::FadeTo
- Defined in:
- lib/chingu/game_states/fade_to.rb
Instance Attribute Summary
Attributes inherited from Chingu::GameState
#game_objects, #game_state_manager, #options
Attributes included from Helpers::InputDispatcher
Instance Method Summary collapse
- #draw ⇒ Object
-
#initialize(new_game_state, options = {}) ⇒ FadeTo
constructor
A new instance of FadeTo.
- #setup ⇒ Object
- #update ⇒ Object
Methods inherited from Chingu::GameState
#button_down, #button_up, #close, #close_game, #to_s, #to_sym
Methods included from Helpers::InputClient
Methods included from Helpers::InputDispatcher
#add_input_client, #dispatch_action, #dispatch_button_down, #dispatch_button_up, #dispatch_input_for, #remove_input_client
Methods included from Helpers::GameObject
#add_game_object, #game_objects, #game_objects_of_class, #remove_game_object
Methods included from Helpers::GameState
#clear_game_states, #current_game_state, #pop_game_state, #previous_game_state, #push_game_state, #switch_game_state, #transitional_game_state
Methods included from Helpers::GFX
#fill, #fill_gradient, #fill_rect
Constructor Details
#initialize(new_game_state, options = {}) ⇒ FadeTo
Returns a new instance of FadeTo.
37 38 39 40 41 42 |
# File 'lib/chingu/game_states/fade_to.rb', line 37 def initialize(new_game_state, = {}) @options = {:speed => 3}.merge() @new_game_state = new_game_state @manager = [:game_state_manager] || self #@manager = game_state_manager end |
Instance Method Details
#draw ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chingu/game_states/fade_to.rb', line 67 def draw # Stop endless loops if @drawn == false @drawn = true if @fading_in @new_game_state.draw else @manager.previous_game_state.draw end $window.draw_quad( 0,0,@color, $window.width,0,@color, $window.width,$window.height,@color, 0,$window.height,@color,999) end if @fading_in && @alpha == 0 @manager.switch_game_state(@new_game_state, :transitional => false) end end |
#setup ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/chingu/game_states/fade_to.rb', line 44 def setup @color = Gosu::Color.new(0,0,0,0) if @manager.previous_game_state @fading_in = false @alpha = 0.0 else @fading_in = true @alpha = 255.0 end # @new_game_state.update # Make sure states game logic is run Once (for a correct draw()) update # Since draw is called before update end |
#update ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/chingu/game_states/fade_to.rb', line 57 def update @alpha += (@fading_in ? -@options[:speed] : @options[:speed]) @alpha = 0 if @alpha < 0 @alpha = 255 if @alpha > 255 @fading_in = true if @alpha == 255 @color.alpha = @alpha.to_i @drawn = false end |