Class: ExampleApp::ZifExampleScene
- Inherits:
-
Zif::Scene
- Object
- Zif::Scene
- ExampleApp::ZifExampleScene
- Includes:
- Zif::Traceable
- Defined in:
- app/scenes/zif_example_scene.rb
Overview
Just some shared functionality across all Zif example app scenes.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next_scene ⇒ Object
Returns the value of attribute next_scene.
-
#scene_timer ⇒ Object
Returns the value of attribute scene_timer.
-
#tracer_service_name ⇒ Object
Returns the value of attribute tracer_service_name.
Instance Method Summary collapse
-
#display_context_labels ⇒ Object
rubocop:disable Layout/LineLength.
- #display_timer_bar ⇒ Object
-
#initialize ⇒ ZifExampleScene
constructor
A new instance of ZifExampleScene.
- #perform_tick ⇒ Object
- #prepare_scene ⇒ Object
Methods included from Zif::Traceable
#mark, #mark_and_print, #mark_prefix, #tracer
Methods inherited from Zif::Scene
Methods included from Zif::Serializable
#exclude_from_serialize, #inspect, #serialize, #to_s
Constructor Details
#initialize ⇒ ZifExampleScene
Returns a new instance of ZifExampleScene.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/scenes/zif_example_scene.rb', line 8 def initialize @tracer_service_name = :tracer @scene_timer = 60 * 60 @pause_timer = false @timer_bar = Zif::Sprite.new @timer_bar.assign( x: 0, y: 718, w: 1280, h: 2, a: 80, z_index: 999, path: 'sprites/white_1.png' ) @timer_bar_set = false end |
Instance Attribute Details
#next_scene ⇒ Object
Returns the value of attribute next_scene.
6 7 8 |
# File 'app/scenes/zif_example_scene.rb', line 6 def next_scene @next_scene end |
#scene_timer ⇒ Object
Returns the value of attribute scene_timer.
6 7 8 |
# File 'app/scenes/zif_example_scene.rb', line 6 def scene_timer @scene_timer end |
#tracer_service_name ⇒ Object
Returns the value of attribute tracer_service_name.
6 7 8 |
# File 'app/scenes/zif_example_scene.rb', line 6 def tracer_service_name @tracer_service_name end |
Instance Method Details
#display_context_labels ⇒ Object
rubocop:disable Layout/LineLength
80 81 82 83 84 85 86 87 88 |
# File 'app/scenes/zif_example_scene.rb', line 80 def display_context_labels color = {r: 255, g: 255, b: 255, a: 255} wait_text = @pause_timer ? '. Paused, press pgup to unpause.' : ", or wait #{@scene_timer} ticks. Press pgup to pause." $gtk.args.outputs.labels << { x: 4, y: 720 - 2, text: "#{self.class.name}. Press pgdown to #{@next_scene}#{wait_text}" }.merge(color) $gtk.args.outputs.labels << { x: 0, y: 720 - 22, text: "#{tracer&.last_tick_ms} #{$gtk.args.gtk.current_framerate}fps" }.merge(color) $gtk.args.outputs.labels << { x: 4, y: 24, text: "Last slowest mark: #{tracer&.slowest_mark}" }.merge(color) $gtk.args.outputs.labels << { x: 4, y: 44, text: "Max slowest mark: #{tracer&.slowest_max_mark}" }.merge(color) $gtk.args.outputs.labels << { x: 4, y: 64, text: "Avg slowest mark: #{tracer&.slowest_avg_mark}" }.merge(color) end |
#display_timer_bar ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/scenes/zif_example_scene.rb', line 56 def unless @timer_bar_set $gtk.args.outputs.static_sprites << @timer_bar @timer_bar_set = true end if @pause_timer @timer_bar.assign( w: 1280, r: 255, g: 0, b: 0 ) else @timer_bar.assign( w: @scene_timer, r: 0, g: 255, b: 180 ) end end |
#perform_tick ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/scenes/zif_example_scene.rb', line 37 def perform_tick $game.services[:tracer].clear_averages if $gtk.args.inputs.keyboard.key_up.delete if $gtk.args.inputs.keyboard.key_up.pageup @pause_timer = !@pause_timer @scene_timer += 100 if @pause_timer end @scene_timer -= 1 unless @pause_timer display_context_labels return unless @next_scene return @next_scene if @force_next_scene || $gtk.args.inputs.keyboard.key_up.pagedown || !@scene_timer.positive? end |
#prepare_scene ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/scenes/zif_example_scene.rb', line 25 def prepare_scene # You probably want to remove the things registered with the services when scenes change # You can remove items explicitly using #remove_.., but #reset_.. will clear everything # You can also do this when a scene is being changed away from, using the #unload_scene method. $game.services[:action_service].reset_actionables $game.services[:input_service].reset tracer.clear_averages $gtk.args.outputs.static_sprites.clear $gtk.args.outputs.static_labels.clear @timer_bar_set = false end |