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?
Constructor Details
#initialize(clip, radius: 1000) ⇒ AudioSource
Returns a new instance of AudioSource.
5
6
7
8
9
|
# File 'lib/engine/components/audio_source.rb', line 5
def initialize(clip, radius: 1000)
@clip = clip
@radius = radius
@source = NativeAudio::AudioSource.new(clip)
end
|
Instance Method Details
#pause ⇒ Object
19
20
21
|
# File 'lib/engine/components/audio_source.rb', line 19
def pause
@source.pause
end
|
#play ⇒ Object
11
12
13
|
# File 'lib/engine/components/audio_source.rb', line 11
def play
@source.play
end
|
#resume ⇒ Object
23
24
25
|
# File 'lib/engine/components/audio_source.rb', line 23
def resume
@source.resume
end
|
#stop ⇒ Object
15
16
17
|
# File 'lib/engine/components/audio_source.rb', line 15
def stop
@source.stop
end
|
#update(delta_time) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/engine/components/audio_source.rb', line 31
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
27
28
29
|
# File 'lib/engine/components/audio_source.rb', line 27
def volume=(volume)
@source.set_volume(volume)
end
|