Class: Engine::Components::AudioSource
Instance Attribute Summary
#game_object
Instance Method Summary
collapse
#_erase!, #destroy, #destroy!, #destroyed?, destroyed_components, erase_destroyed_components, method_added, #renderer?, #set_game_object, #start, #ui_renderer?
allowed_class?, get_class, included, register_class, #uuid
Instance Method Details
#awake ⇒ Object
7
8
9
10
11
|
# File 'lib/engine/components/audio_source.rb', line 7
def awake
@radius ||= 1000
@clip = NativeAudio::Clip.new(@clip_path)
@source = NativeAudio::AudioSource.new(@clip)
end
|
#pause ⇒ Object
21
22
23
|
# File 'lib/engine/components/audio_source.rb', line 21
def pause
@source.pause
end
|
#play ⇒ Object
13
14
15
|
# File 'lib/engine/components/audio_source.rb', line 13
def play
@source.play
end
|
#resume ⇒ Object
25
26
27
|
# File 'lib/engine/components/audio_source.rb', line 25
def resume
@source.resume
end
|
#stop ⇒ Object
17
18
19
|
# File 'lib/engine/components/audio_source.rb', line 17
def stop
@source.stop
end
|
#update(delta_time) ⇒ Object
33
34
35
36
37
38
39
40
41
|
# File 'lib/engine/components/audio_source.rb', line 33
def update(delta_time)
camera = Engine::Camera.instance
local_pos = camera.game_object.world_to_local_coordinate(game_object.pos)
angle = Math.atan2(local_pos[0], -local_pos[2]) * 180 / Math::PI
angle = (angle + 360) % 360
distance = (local_pos.magnitude * 255 / @radius).clamp(0, 255)
@source.set_pos(angle, distance)
end
|
#volume=(volume) ⇒ Object
29
30
31
|
# File 'lib/engine/components/audio_source.rb', line 29
def volume=(volume)
@source.set_volume(volume)
end
|