Sound는 소리를 방출하는 개체입니다.이 개체는 BasePart 또는 Attachment 에 배치되면 해당 부분의 BasePart.Position 또는 부착물의 Attachment.WorldPosition 에서 소리를 방출합니다.이 배치에서 Sound 는 도플러 효과를 보여주며, 즉 주어진 부착물이나 부품의 상대적 이동에 따라 주파수와 피치가 변합니다.또한, 볼륨은 클라이언트의 사운드 리스너(기본적으로 Camera 위치)와 사운드의 부모 위치 사이의 거리에 의해 결정됩니다.자세한 내용은 RollOffMode를 참조하십시오.
소리가 부모로 지정되지 않았거나 또는 BasePart 또는 Attachment에 부모로 지정되지 않은 경우 소리는 "전역"으로 간주됩니다.이 경우 소리는 전체 플레이스동일한 볼륨으로 재생됩니다.
코드 샘플
이 샘플의 코드는 파트나 부착물에 부모로 지정된 소리가 플레이어의 카메라가 부품에서 멀어질수록 로컬로 재생되고 플레이어의 카메라가 부품에서 멀어질수록 볼륨이 감소하는 방법을 보여줍니다.
부품이 인스턴스화되고 사운드가 부품에 인스턴스화되고 부모로 지정됩니다.클릭 감지기는 Sound.IsPlaying를 사용하여 소리가 재생되는지 확인하는 부품에 설정되며, 소리를 재생하거나 중지하는지 여부는 사운드에 따라 달라집니다.
local part = Instance.new("Part")
part.Anchored = true
part.Position = Vector3.new(0, 3, 0)
part.BrickColor = BrickColor.new("Bright red")
part.Name = "MusicBox"
part.Parent = workspace
-- 사운드 생성
local sound = Instance.new("Sound", part)
sound.SoundId = "rbxassetid://9120386436"
sound.EmitterSize = 5 -- 발신기 크기 줄이기(이전 볼륨 드롭오프)
sound.Looped = true
sound.Parent = part
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = part
-- 소리 재생/재생 안 하기 전환
clickDetector.MouseClick:Connect(function()
if not sound.IsPlaying then
part.BrickColor = BrickColor.new("Bright green")
sound:Play()
else
part.BrickColor = BrickColor.new("Bright red")
sound:Stop()
end
end)
요약
속성
이 속성은 Roblox 서버에서 로드되어 플레이할 준비가 된 Sound 가 있을 때 true입니다.
읽기 전용 속성으로, true 가 재생되지 않을 때 Sound 를 반환합니다.
읽기 전용 속성으로, true가 재생될 때 Sound를 반환합니다.
PlaybackRegion 내에서 원하는 루프 시작 및 루프 끝을 나타내는 범위, 초 단위.
재생이 완료되면 반복할지 여부를 Sound로 설정합니다.
When true , the Sound 는 경험에서 제거될 때 재생됩니다.
현재 0 재생 중인 1000 의 볼륨을 나타내는 숫자, Sound 사이의 숫자는 뒤로볼륨을 나타냅니다.
TimeLength 내에서 원하는 시작 및 종료 시간을 나타내는 범위, 초 단위.
만약 , 이 속성은 더 정확하게 재생을 제어할 수 있는 및 속성에 대한 액세스를 제공합니다.
더 높은 값으로 인해 소리가 더 빠르게 플레이더 높은 피치로 재생되는 속도를 결정합니다 Sound 에서 재생할 때.
현재 Sound가 재생 중인지 여부를 나타냅니다.
클라이언트의 리스너가 소리의 원천에서 최대 거리, 스터드로, 여전히 들을 수 있습니다.부모로 지정된 Sounds 또는 BasePart 또는 Attachment에만 적용됩니다.
부모에게 속한 Sound 또는 BasePart 또는 Attachment 가 약화되기 시작하는 최소 거리, 스터드로,는 다음과 같습니다.
부모로 지정된 의 볼륨이 리스너와 부모 사이의 거리가 변경됨에 따라 어떻게 감소(사라짐)하는지 제어합니다.
이 SoundGroup 에 연결된 것은 이 Sound 입니다.
Sound와 연결할 사운드 파일의 콘텐츠 ID.
초 단위의 Sound 길이.
초당 Sound 의 진행률. 재생 위치를 이동하기 위해 Sound 의 재생 전과 재생 중에 변경할 수 있습니다.
Sound의 볼륨.
메서드
이벤트
속성
ChannelCount
IsLoaded
이 속성은 Roblox 서버에서 로드되어 플레이할 준비가 된 Sound 가 있을 때 true입니다.이 속성과 Loaded 이벤트를 사용하여 플레이하기 전에 사운드가 로드되었는지 확인할 수 있습니다.
코드 샘플
This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.
It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")
IsPaused
이 읽기 전용 속성은 true 플레이하지 않을 때 Sound 를 반환합니다.소리가 을 사용하여 일시 중지되었거나, 을 사용하여 중지되었거나, 소리가 재생된 적이 없는 경우 을 반환할 수 있습니다.
읽기 전용인 As IsPaused는 소리를 멈추게 하는 데 사용할 수 없으며, Stop() 또는 Pause() 대신 사용해야 합니다.
코드 샘플
이 코드 샘플에서는 Sound.IsPlaying 및 Sound.IsPaused 속성이 참이나 거짓인지 여부를 보여줍니다.
작업 공간에 사운드가 인스턴스화되고 Sound.IsLoaded 속성이 확인되어 사운드가 로드되었는지 확인합니다. 사운드가 없으면 Sound.Loaded 이벤트가 사용되어 사운드가 있을 때까지 스크립트를 렌더링합니다.
소리가 재생, 일시 중지 및 중지되면 Sound.IsPlaying 및 Sound.IsPaused 속성이 인쇄되어 이러한 기능에 대해 어떻게 반응하는지 보여줍니다.일시 중지가 아닌 소리가 재생되는 경우에도 Note Sound.IsPaused는 항상 true가 됩니다.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
if not sound.isLoaded then
sound.Loaded:Wait()
end
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- 참, 아니요
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- 거짓, 진실
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- 참, 아니요
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- false, true
IsPlaying
이 읽기 전용 속성은 Sound가 재생될 때 true를 반환합니다.
읽기 전용인 As IsPlaying는 소리를 재생하는 데 사용할 수 없으므로 대신 Play()를 사용해야 합니다.
코드 샘플
이 코드 샘플에서는 Sound.IsPlaying 및 Sound.IsPaused 속성이 참이나 거짓인지 여부를 보여줍니다.
작업 공간에 사운드가 인스턴스화되고 Sound.IsLoaded 속성이 확인되어 사운드가 로드되었는지 확인합니다. 사운드가 없으면 Sound.Loaded 이벤트가 사용되어 사운드가 있을 때까지 스크립트를 렌더링합니다.
소리가 재생, 일시 중지 및 중지되면 Sound.IsPlaying 및 Sound.IsPaused 속성이 인쇄되어 이러한 기능에 대해 어떻게 반응하는지 보여줍니다.일시 중지가 아닌 소리가 재생되는 경우에도 Note Sound.IsPaused는 항상 true가 됩니다.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
if not sound.isLoaded then
sound.Loaded:Wait()
end
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- 참, 아니요
task.wait(2)
sound:Pause()
print(sound.IsPlaying, sound.IsPaused) -- 거짓, 진실
task.wait(2)
sound:Play()
print(sound.IsPlaying, sound.IsPaused) -- 참, 아니요
task.wait(2)
sound:Stop()
print(sound.IsPlaying, sound.IsPaused) -- false, true
LoopRegion
PlaybackRegion 내에서 원하는 루프 시작 및 루프 끝을 나타내는 범위, 초 단위.
만약 Class.Sound.LoopRegion|LoopRegion.Min``>``Class.Sound.PlaybackRegion|PlaybackRegion.Min , 루프는 LoopRegion.Min 에서 시작됩니다.
만약 Class.Sound.LoopRegion|LoopRegion.Min``<``Class.Sound.PlaybackRegion|PlaybackRegion.Min , 루프는 PlaybackRegion.Min 에서 시작됩니다.
만약 Class.Sound.LoopRegion|LoopRegion.Max``>``Class.Sound.PlaybackRegion|PlaybackRegion.Max , 루프는 PlaybackRegion.Max 에서 시작됩니다.
만약 , 루프는 그 시간에 정확히 시작합니다.
만약 Class.Sound.LoopRegion|LoopRegion.Min``==``Class.Sound.LoopRegion|LoopRegion.Max , 그 다음 Sound 은 대신 속성 PlaybackRegion 을 사용합니다.
Looped
이 설정은 재생이 완료되면 Sound 반복 여부를 결정합니다.루프된 사운드는 음악과 배경 환경 사운드를 포함한 다양한 응용 프로그램에 적합합니다.
DidLoop 이벤트를 사용하여 소리가 루프된 횟수를 추적할 수 있습니다.
코드 샘플
This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.
local function loopNTimes(sound, numberOfLoops)
if not sound.IsPlaying then
sound.Looped = true
local connection = nil
connection = sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
print(numOfTimesLooped)
if numOfTimesLooped >= numberOfLoops then
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)
PlayOnRemove
When true , the Sound 는 경험에서 제거되어 부모가 Sound 또는 조상이 nil 인 경우 재생할 것입니다.즉, 다음 모든 것이 PlayOnRemove에서 소리가 재생되도록 만들 때 true :
- sound:Destroy()
- sound.Parent = nil
- sound.Parent.Parent = nil
PlaybackLoudness
현재 0 재생 중인 1000 의 볼륨을 나타내는 숫자, Sound 사이의 숫자는 뒤로볼륨을 나타냅니다.이 속성은 읽음시점의 인스턴스에서 소리의 재생 범위를 반영합니다.
코드 샘플
In this sample Sound.PlaybackLoudness is used to create an amplitude bar that shows the amplitude of a sound playing.
This code sample should be placed in StarterPlayerScripts.
A simple GUI is created, a frame holding that bar and a frame containing the bar. A Sound is then played and the size of the bar is set to reflect the Sound.PlaybackLoudness on a loop.
-- to be placed in StarterPlayer > StarterPlayerScripts
local Players = game:GetService("Players")
-- wait for local player PlayerGui
local LocalPlayer = Players.LocalPlayer
local playerGui = LocalPlayer:WaitForChild("PlayerGui")
-- create a ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = playerGui
-- create a holder for our bar
local frame = Instance.new("Frame")
frame.AnchorPoint = Vector2.new(0.5, 0.5)
frame.Position = UDim2.new(0.5, 0, 0.5, 0)
frame.Size = UDim2.new(0.3, 0, 0.05, 0)
frame.Parent = screenGui
-- create a bar
local bar = Instance.new("Frame")
bar.Position = UDim2.new(0, 0, 0, 0)
bar.Size = UDim2.new(1, 0, 1, 0)
bar.BackgroundColor3 = Color3.new(0, 1, 0)
bar.Parent = frame
-- create a sound
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = screenGui
sound:Play()
-- define a max loudness
local maxLoudness = 30
-- animate the amplitude bar
while true do
local amplitude = math.clamp(sound.PlaybackLoudness / maxLoudness, 0, 1)
bar.Size = UDim2.new(amplitude, 0, 1, 0)
wait(0.05)
end
PlaybackRegion
TimeLength 내에서 원하는 시작 및 종료 시간을 나타내는 범위, 초 단위.
If PlaybackRegion.Min``>``0 , 소리가 PlaybackRegion.Min 시간부터 재생하기 시작합니다.
만약 PlaybackRegion.Min``<``0 , 소리가 0 에서 재생하기 시작합니다.
If PlaybackRegion.Max``>``Class.Sound.TimeLength , 소리가 중지됩니다 Sound.TimeLength .
만약 , 소리는 그 시간에 정확히 에 멈춥니다.
만약 Class.Sound.PlaybackRegion|PlaybackRegion.Min``==``Class.Sound.PlaybackRegion|PlaybackRegion.Max , 이 속성은 비활성입니다.
PlaybackSpeed
더 높은 값으로 인해 소리가 더 빠르게 플레이더 높은 피치로 재생되는 속도를 결정합니다 Sound 에서 재생할 때.
코드 샘플
이 예제에서는 작업 공간에서 사운드가 재생됩니다.플레이백 속도 속성은 간격을 두고 증가하고 감소하여 사운드 재생에 미치는 영향을 보여줍니다.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
sound:Play()
task.wait(10)
sound.PlaybackSpeed = 3 -- 3배 빠르게
task.wait(5)
sound.PlaybackSpeed = 0.5 -- 2배 느림
task.wait(5)
sound.PlaybackSpeed = 1 -- default
Playing
현재 Sound 가 재생 중인지 여부를 나타냅니다. 이 속성은 전환할 수 있으며 항상 복제됩니다.
Studio의 속성 창에서, 편집 모드에 있는 동안, Playing``true 전환하면 소리가 재생되기 시작하지 않지만 런타임에 소리가 재생되기 시작합니다.
이 속성은 읽기 전용 속성인 IsPlaying와 혼동되어서는 안됩니다.
Playing가 false로 설정되면 사운드의 TimePosition 속성이 재설정되지 않으므로, Playing가 true로 다시 설정되면 오디오가 중지되었을 때의 시간 위치에서 계속됩니다.그러나 소리를 재개하기 위해 Play() 함수가 사용되면 시간 위치가 0로 재설정됩니다.
코드 샘플
This sample demonstrates how the Sound.Playing property can be used to start and stop playback of a sound.
A sound is instanced in the Workspace and playback is started by setting Sound.Playing to true. After ten seconds the playback is stopped by setting Sound.Playing to false. When the playback is again resumed using Sound.Playing it resumes at the previous Sound.TimePosition it was stopped at. This is demonstrated by printing the TimePosition property immediately after resuming the sound.
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Looped = true
sound.Parent = workspace
print("playing sound")
sound.Playing = true
task.wait(10)
print("stopping sound")
sound.Playing = false
task.wait(5)
sound.Playing = true
local timePosition = sound.TimePosition
print("resumed at time position: " .. tostring(timePosition)) -- c. 10 seconds
RollOffMaxDistance
클라이언트의 리스너가 소리의 원천에서 최대 거리, 스터드로, 여전히 들을 수 있습니다.부모로 지정된 Sounds 또는 BasePart 또는 Attachment에만 적용됩니다.
소리의 약화에 미치는 방식 RollOffMaxDistance 은 속성 RollOffMode 에 달려 있습니다.
RollOffMinDistance
부모에게 속한 Sound 또는 BasePart 또는 Attachment 가 약화되기 시작하는 최소 거리, 스터드로,는 다음과 같습니다.
소리의 약화에 미치는 방식 RollOffMinDistance 은 속성 RollOffMode 에 달려 있습니다.
RollOffMode
이 속성은 부모로 지정된 Sound 또는 BasePart 또는 Attachment 의 볼륨이 리스너와 부모 간의 거리가 변경됨에 따라 어떻게 감소(사라짐)하는지 제어합니다.
다양한 모드에 대한 자세한 내용은 Enum.RollOffMode를 참조하십시오.
TimeLength
초 단위의 Sound 길이. Sound 가 로드되지 않으면 이 값이 0 됩니다.
이 속성은 종종 PlaybackSpeed와 함께 사용되어 소리의 속도를 조정하여 특정 기간 동안 지속됩니다.
코드 샘플
This code sample includes a simple function that uses Sound.TimeLength and Sound.PlaybackSpeed to play a sound that'll take the given duration to complete. It achieves this by setting the PlaybackSpeed of the sound to be equal to the TimeLength of the sound divided by the desired duration.
Note that as TimeLength is equal to 0 when the sound has not loaded, the function will yield while it loads the sound.
local function playForDuration(sound, duration)
if not sound.IsLoaded then
sound.Loaded:wait()
end
local speed = sound.TimeLength / duration
sound.PlaybackSpeed = speed
sound:Play()
end
local sound = script.Parent
playForDuration(sound, 5)
TimePosition
이 속성은 초당 Sound의 진행률을 반영합니다.재생 위치를 바꿔서 재생 전과 재생 중에 모두 사운드의 재생 위치를 이동할 수 있습니다.
재생되는 동안 는 초당 속도로 증가합니다.한 번 에 도달하면, 소리가 이 아니면 중지됩니다.
반복된 트랙의 길이보다 큰 값으로 TimePosition 설정을 변경하면 감싸지지 않습니다.해당 동작이 원하는 경우 다음 코드 스니펫을 고려하십시오:
local newPosition = 1.5if newPosition >= sound.TimeLength thennewPosition = newPosition - sound.TimeLengthendsound.TimePosition = newPosition
코드 샘플
This sample demonstrates how Sound.TimePosition can be used to jump to particular points in an audio file both before and during Sound playback.
A Sound is created in the Workspace and set to start at 30 seconds in. During playback, it jumps forwards to 100 seconds and then back to the start (0 seconds).
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://9120386436"
sound.Parent = workspace
sound.TimePosition = 30
sound:Play()
task.wait(5)
sound.TimePosition = 100
task.wait(5)
sound.TimePosition = 0
메서드
Pause
이 메서드는 재생 중이면 Sound 의 재생을 일시 중지하고, Playing 를 false 로 설정합니다.Stop() 와는 달리, TimePosition 를 재설정하지 않으므로 소리를 Resume() 을 사용하여 재시작할 수 있습니다.
반환
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Play
이 메서드는 Sound 를 재생하고 스크립트에 의해 설정된 마지막 값으로 TimePosition 를 설정한 다음 0에서 설정되지 않은 경우 Playing에 대해 true로 설정합니다.
반환
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Resume
이 메서드는 Sound를 재개하고 Playing를 true로 설정합니다.TimePosition 을 변경하지 않으므로 Pause() 를 통해 일시 중지된 소리의 재생을 재개하는 데 사용할 수 있습니다.
반환
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Stop
이 메서드는 Sound 를 중지하고 Playing 를 false 로 설정한 다음 TimePosition 을 0 로 설정합니다.
반환
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
이벤트
DidLoop
반복문 Sound가 실행될 때마다 발생합니다.반환 soundId 및 numOfTimesLooped , 소리의 콘텐츠 ID와 반복된 횟수를 각각 제공합니다.
Sound를 통해 Stop()로 중지되면 루프된 카운터가 재설정되어 다음 DidLoop 이벤트가 반환됩니다 1 대于 numOfTimesLooped.
매개 변수
코드 샘플
This code sample includes a function that will play a sound and allow it to loop for a given number of times before stopping it.
local function loopNTimes(sound, numberOfLoops)
if not sound.IsPlaying then
sound.Looped = true
local connection = nil
connection = sound.DidLoop:Connect(function(_soundId, numOfTimesLooped)
print(numOfTimesLooped)
if numOfTimesLooped >= numberOfLoops then
-- disconnect the connection
connection:Disconnect()
-- stop the sound
sound:Stop()
end
end)
sound:Play()
end
end
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://0"
loopNTimes(sound, 5)
Ended
Sound가 재생을 완료하고 중지했을 때 발생합니다. 이 이벤트는 재생이 완료되었을 때 소리를 파괴하는 데 자주 사용됩니다.
sound:Play()sound.Ended:Wait()sound:Destroy()
이 이벤트는 끝에 도달하면 계속 재생되는 소리에 대해 발사하지 않을 것이라는 점에 유의하십시오. as they continue playing upon reaching their end.이 이벤트는 재생이 완료되기 전에 소리가 중지되면 또한 발생하지 않습니다; 이 용도로는 이벤트를 사용하십시오.
매개 변수
Loaded
Sound 가 로드될 때 화재가 발생합니다.
이 이벤트는 사운드가 로드될 때만 발생하므로, 이 이벤트에 연결하기 전에 사운드의 IsLoaded 속성을 확인하는 것이 좋습니다.
매개 변수
코드 샘플
This simple function will verify a Sound has loaded by checking the Sound.IsLoaded property. If Sound.IsLoaded is false it will wait for the Loaded event before resuming.
It is important to check Sound.IsLoaded before connecting to the Sound.Loaded event, as if the sound has already loaded the Sound.Loaded event will not fire and the function will yield indefinitely.
local sound = script.Parent.Sound
if not sound.IsLoaded then
sound.Loaded:Wait()
end
print("The sound has loaded!")
Paused
Sound를 사용하여 일시 중지되면 언제든지 발생합니다. 발생할 때마다 Pause()에 의해 중지됩니다.
매개 변수
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Played
Sound를 사용하여 재생될 때마다 발생합니다. Play()에서 재생됩니다.이 이벤트는 발생하지 않을 것입니다 만약 가 재생되어 소리가 파괴되고 설정이 로 변경되면.
매개 변수
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Resumed
를 사용하여 재시작할 때 화재가 발생합니다.
매개 변수
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0
Stopped
Sound를 사용하여 중지하면 Stop()를 재생하는 동안 소리를 파괴하면 이 이벤트가 발생하지 않습니다.
매개 변수
코드 샘플
이 샘플은 각 사운드 함수(Sound.Play, Sound.Stop, Sound.Pause 및 Sound.Resume)가 사운드.플레이와 사운드.타임포지션에 수행하는 간단한 시연을 제공합니다.
-- 사운드 생성
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://9120386436"
if not sound.IsLoaded then
sound.Loaded:Wait()
end
-- 이벤트 수신 listen for events
sound.Played:Connect(function(_soundId)
print("Sound.Played event")
end)
sound.Paused:Connect(function(_soundId)
print("Sound.Paused event")
end)
sound.Resumed:Connect(function(_soundId)
print("Sound.Resumed event")
end)
sound.Stopped:Connect(function(_soundId)
print("Sound.Stopped event")
end)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진실 0
task.wait(10)
sound:Pause()
print("pause", sound.Playing, sound.TimePosition) -- 일시 중지 false 10
task.wait(3)
sound:Resume()
print("play", sound.Playing, sound.TimePosition) -- 플레이 진정한 10
task.wait(3)
sound:Stop()
print("stop", sound.Playing, sound.TimePosition) -- 가짜 0 중지
task.wait(3)
sound:Play()
print("play", sound.Playing, sound.TimePosition) -- play true 0