Class: AdventureRL::ClipPlayer
- Inherits:
-
FileGroupPlayer
- Object
- FileGroupPlayer
- AdventureRL::ClipPlayer
- Defined in:
- lib/AdventureRL/ClipPlayer.rb
Constant Summary collapse
- DEFAULT_SETTINGS =
Default settings for ClipPlayer. Are superseded by settings passed to #new.
Settings.new({ speed: 1.0, loop: true, mask: { position: { x: 0, y: 0 }, size: { width: 960, height: 540 }, origin: { x: :left, y: :top } }, z_index: 0, color: 0xff_ffffff, image_options: { retro: true } })
- AUDIO_PLAYER_METHODS =
[ :pause, :resume, :stop, :reset, :set_current_time, :increase_current_time, :set_speed, :increase_speed, :update ]
Constants included from Helpers::Error
Helpers::Error::PADDING, Helpers::Error::STACK_TRACE_PADDING, Helpers::Error::STACK_TRACE_SIZE
Class Method Summary collapse
-
.define_audio_player_methods ⇒ Object
Overwrite a bunch of FileGroupPlayer methods, so they also handle Audio, if Clip has one.
-
.get_aliased_methods(method_name) ⇒ Object
Returns the method names of all methods aliased to method
method_name.
Instance Method Summary collapse
-
#draw ⇒ Object
Draw the current image in the currently active Clip.
-
#get_audio_player ⇒ Object
Returns the current AudioPlayer, if there is one.
-
#has_audio_player? ⇒ Boolean
Returns true if an AudioPlayer was instantiated for this ClipPlayer.
-
#initialize(settings = {}) ⇒ ClipPlayer
constructor
Pass settings Hash or Settings as argument.
-
#play(*args) ⇒ Object
Overwrite FileGroupPlayer#play separately from above, because it should call #handle_play_for_audio_player to create a new AudioPlayer, if necessary.
Methods inherited from FileGroupPlayer
#get_current_time, #get_filegroup, #get_settings, #get_speed, #has_filegroup?, #increase_current_time, #increase_speed, #is_playing?, #load_filegroup, #pause, #reset, #resume, #set_current_time, #set_speed, #stop, #toggle, #update
Methods included from Helpers::Error
directory_exists?, error, error_no_directory, error_no_file, file_exists?
Constructor Details
#initialize(settings = {}) ⇒ ClipPlayer
Pass settings Hash or Settings as argument. Supersedes DEFAULT_SETTINGS.
75 76 77 78 79 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 75 def initialize settings = {} super @audio_player = nil set_mask_from get_settings(:mask) end |
Class Method Details
.define_audio_player_methods ⇒ Object
Overwrite a bunch of FileGroupPlayer methods, so they also handle Audio, if Clip has one. See AUDIO_PLAYER_METHODS for the list of methods.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 55 def define_audio_player_methods AUDIO_PLAYER_METHODS.each do |real_method_name| [real_method_name, get_aliased_methods(real_method_name)].flatten.each do |method_name| define_method(method_name) do |*args| super *args get_audio_player.method(method_name).call(*args) if (has_audio_player?) # NOTE: Write #sync_audio_player method, maybe? # Should be unnecessarilty doubled work, # but it would garantee that both Players are synced. # sync_audio_player end end end end |
.get_aliased_methods(method_name) ⇒ Object
Returns the method names of all methods aliased to method method_name.
42 43 44 45 46 47 48 49 50 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 42 def get_aliased_methods method_name real_method = instance_method method_name return instance_methods.select do |instance_method_name| next ( real_method == instance_method(instance_method_name) && method_name != instance_method_name ) end end |
Instance Method Details
#draw ⇒ Object
Draw the current image in the currently active Clip. This should be called every frame.
111 112 113 114 115 116 117 118 119 120 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 111 def draw image = get_current_file return unless (image) scale = get_scale_for_image image image.draw( get_side(:left), get_side(:top), get_settings(:z_index), scale[:x], scale[:y], get_settings(:color) ) end |
#get_audio_player ⇒ Object
Returns the current AudioPlayer, if there is one.
82 83 84 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 82 def get_audio_player return @audio_player end |
#has_audio_player? ⇒ Boolean
Returns true if an AudioPlayer was instantiated for this ClipPlayer.
87 88 89 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 87 def has_audio_player? return !!get_audio_player end |
#play(*args) ⇒ Object
Overwrite FileGroupPlayer#play separately from above, because it should call #handle_play_for_audio_player to create a new AudioPlayer, if necessary.
102 103 104 105 106 107 |
# File 'lib/AdventureRL/ClipPlayer.rb', line 102 def play *args super if (get_clip.has_audio?) handle_play_for_audio_player end end |