class AdventureRL::ClipPlayer
Constants
- AUDIO_PLAYER_METHODS
- DEFAULT_SETTINGS
Default settings for
ClipPlayer
. Are superseded by settings passed to new.
Public Class Methods
Overwrite a bunch of FileGroupPlayer
methods, so they also handle Audio
, if Clip
has one. See AUDIO_PLAYER_METHODS
for the list of methods.
# 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
Returns the method names of all methods aliased to method method_name
.
# 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
Pass settings Hash or Settings
as argument. Supersedes DEFAULT_SETTINGS
.
# File lib/AdventureRL/ClipPlayer.rb, line 75 def initialize settings = {} super @audio_player = nil set_mask_from get_settings(:mask) end
Public Instance Methods
Draw the current image in the currently active Clip
. This should be called every frame.
# 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
Returns the current AudioPlayer
, if there is one.
# File lib/AdventureRL/ClipPlayer.rb, line 82 def get_audio_player return @audio_player end
Returns true if an AudioPlayer
was instantiated for this ClipPlayer
.
# File lib/AdventureRL/ClipPlayer.rb, line 87 def has_audio_player? return !!get_audio_player end
Overwrite FileGroupPlayer#play
separately from above, because it should call handle_play_for_audio_player
to create a new AudioPlayer
, if necessary.
# File lib/AdventureRL/ClipPlayer.rb, line 102 def play *args super if (get_clip.has_audio?) handle_play_for_audio_player end end
Private Instance Methods
Returns this class' DEFAULT_SETTINGS
.
# File lib/AdventureRL/ClipPlayer.rb, line 183 def get_default_settings return DEFAULT_SETTINGS end
# File lib/AdventureRL/ClipPlayer.rb, line 159 def get_scale_for_image image = get_current_file return { x: (get_size(:width).to_f / image.width.to_f), y: (get_size(:height).to_f / image.height.to_f) } end
Create, change, or remove AudioPlayer
, depending on if the current Clip
has Audio
.
# File lib/AdventureRL/ClipPlayer.rb, line 168 def handle_play_for_audio_player clip = get_clip if (clip.has_audio?) if (has_audio_player?) @audio_player.play clip.get_audio else @audio_player = AudioPlayer.new get_settings @audio_player.play clip.get_audio end elsif (has_audio_player?) get_audio_player.stop end end
Loads the image file file
# File lib/AdventureRL/ClipPlayer.rb, line 140 def load_file file if (get_current_image.is_a? Gosu::Image) get_current_image.insert file, 0, 0 else set_current_image Gosu::Image.new( file, get_settings(:image_options) ) end end
Set the Mask
for the ClipPlayer
.
# File lib/AdventureRL/ClipPlayer.rb, line 125 def set_mask_from mask if (mask.is_a?(Mask)) mask.assign_to self elsif (mask.is_a?(Hash)) Mask.new( mask.merge( assign_to: self ) ) else error "Cannot set Mask as #{mask.inspect}:#{mask.class.name} for ClipPlayer." end end