Ver código fonte

Changed from play_sound and stop_sound messages to function calls

Björn Ritzl 6 anos atrás
pai
commit
dbfa216367

+ 1 - 1
docs/en/manuals/animation.md

@@ -216,7 +216,7 @@ function on_message(self, message_id, message, sender)
     -- Play animation sound. The custom event data contains the sound component and the gain.
     local url = msg.url("sounds")
     url.fragment = message.string
-    msg.post(url, "play_sound", { gain = message.float })
+    sound.play(url, { gain = message.float })
   end
 end
 ```

+ 4 - 4
docs/en/manuals/glossary.md

@@ -113,15 +113,15 @@ The Lua programming language is used in Defold to create game logic. Lua is a po
 
 ## Message
 
-Components communicate with each other and other systems through message passing. Components also respond to a set of predefined messages that alter them or trigger specific actions. You send messages to hide graphics, play sounds or nudge physics objects. The engine also uses messages to notify components of events, for instance when physics shapes collide. The message passing mechanism needs a recipient for each sent message. Therefore, everything in the game is uniquely addressed. To allow communication between objects, Defold extends Lua with message passing. Defold also provides a library of useful functions.
+Components communicate with each other and other systems through message passing. Components also respond to a set of predefined messages that alter them or trigger specific actions. You send messages to hide graphics or nudge physics objects. The engine also uses messages to notify components of events, for instance when physics shapes collide. The message passing mechanism needs a recipient for each sent message. Therefore, everything in the game is uniquely addressed. To allow communication between objects, Defold extends Lua with message passing. Defold also provides a library of useful functions.
 
-For instance, the Lua-code required to play an explosion sound from a game object looks like this:
+For instance, the Lua-code required to hide a sprite component on a game object looks like this:
 
 ```lua
-msg.post("#explosion", "play_sound")
+msg.post("#weapon", "disable")
 ```
 
-Here, `"#explosion"` is the address of the current object's sound component. `"play_sound"` is a message that sound components respond to. See the [Message passing documentation](/manuals/message-passing) for an in depth explanation of how message passing works.
+Here, `"#weapon"` is the address of the current object's sprite component. `"disable"` is a message that sprite components respond to. See the [Message passing documentation](/manuals/message-passing) for an in depth explanation of how message passing works.
 
 ## Model
 

+ 9 - 9
docs/en/manuals/sound.md

@@ -37,23 +37,23 @@ The created component has a set of properties that should be set:
 
 ## Playing the sound
 
-When you have a sound component set up properly, you can cause it to play its sound by sending it a ["play_sound"](https://www.defold.com/ref/sound/#play_sound) message:
+When you have a sound component set up properly, you can cause it to play its sound by calling [`sound.play()`](https://www.defold.com/ref/sound/#sound.play:url--play_properties-):
 
 ```lua
-msg.post("go#sound", "play_sound", {delay = 1, gain = 0.5})
+sound.play("go#sound", {delay = 1, gain = 0.5})
 ```
 
 ::: sidenote
-A sound will continue to play even if the game object the sound component belonged to is deleted. You can send a ["stop_sound"](https://www.defold.com/ref/sound/#play_sound) message to stop the sound (see below).
+A sound will continue to play even if the game object the sound component belonged to is deleted. You can call [`sound.stop()`](https://www.defold.com/ref/sound/#sound.stop:url) to stop the sound (see below).
 :::
 Each message sent to a component will cause it to play another instance of the sound, until the available sound buffer is full and the engine will print errors in the console. It is advised that you implement some sort of gating and sound grouping mechanism.
 
 ## Stopping the sound
 
-If you wish to stop playing a sound you can send a ["stop_sound"](https://www.defold.com/ref/sound/#play_sound) message:
+If you wish to stop playing a sound you can call [`sound.stop()`](https://www.defold.com/ref/sound/#sound.stop:url):
 
 ```lua
-msg.post("go#sound", "stop_sound")
+sound.stop("go#sound")
 ```
 
 ## Gain
@@ -63,7 +63,7 @@ msg.post("go#sound", "stop_sound")
 The sound system has 4 levels of gain:
 
 - The gain set on the sound component.
-- The gain set when starting the sound via a `play_sound` message or when changing the gain on the voice via a `set_gain` message.
+- The gain set when starting the sound via a call to `sound.play()` or when changing the gain on the voice via a call to `sound.set_gain()`.
 - The gain set on the group via a [`sound.set_group_gain()`](/ref/sound#sound.set_group_gain) function call.
 - The gain set on the "master" group. This can be altered by `sound.set_group_gain(hash("master"))`.
 
@@ -156,8 +156,8 @@ function on_message(self, message_id, message, sender)
         if self.sounds[message.soundcomponent] == nil then
             -- Store sound timer in table
             self.sounds[message.soundcomponent] = gate_time
-            -- Redirect the "play_sound" message to the real target
-            msg.post(message.soundcomponent, "play_sound", { gain = message.gain })
+            -- Play the sound
+            sound.play(message.soundcomponent, { gain = message.gain })
         else
             -- An attempt to play a sound was gated
             print("gated " .. message.soundcomponent)
@@ -166,7 +166,7 @@ function on_message(self, message_id, message, sender)
 end
 ```
 
-To use the gate, simply send it a `play_gated_sound` message and specify the target sound component and sound gain. The gate will send a `play_sound` message to the target sound component if the gate is open:
+To use the gate, simply send it a `play_gated_sound` message and specify the target sound component and sound gain. The gate will call `sound.play()` with the target sound component if the gate is open:
 
 ```lua
 msg.post("/sound_gate#script", "play_gated_sound", { soundcomponent = "/sounds#explosion1", gain = 1.0 })

+ 2 - 2
docs/ko/manuals/animation.md

@@ -183,7 +183,7 @@ function on_message(self, message_id, message, sender)
     -- 애니메이션 사운드 플레이하기. 커스텀 이벤트 데이터에 사운드 컴포넌트 이름과 출력값(gain)이 들어 있음
     local url = msg.url("sounds")
     url.fragment = message.string
-    msg.post(url, "play_sound", { gain = message.float })
+    sound.play(url, { gain = message.float })
   end
 end
 ```
@@ -251,7 +251,7 @@ go.cancel_animation(".", "euler.z")
 [Properties](/manuals/properties) 매뉴얼에 게임 오브젝트, 컴포넌트, GUI노드의 모든 속성들에 대한 설명이 있습니다.
 
 ### GUI node property animation
-대부분의 모든 GUI 노드 속성들은 애니메이션 가능합니다. 예를 들어, "color" 속성을 설정해서 투명값을 조절하여 노드를 보이지 않게 만든 후에, 색상을 하얗게(tint 컬러가 아님) 애니메이션 처리해서 페이드인 효과를 줄 수 있습니다. 
+대부분의 모든 GUI 노드 속성들은 애니메이션 가능합니다. 예를 들어, "color" 속성을 설정해서 투명값을 조절하여 노드를 보이지 않게 만든 후에, 색상을 하얗게(tint 컬러가 아님) 애니메이션 처리해서 페이드인 효과를 줄 수 있습니다.
 
 ```lua
 local node = gui.get_node("button")

+ 1 - 3
docs/ko/manuals/sound.md

@@ -120,8 +120,7 @@ function on_message(self, message_id, message, sender)
         if self.sounds[message.soundcomponent] == nil then
             -- 테이블에 사운드 타이머를 저장함
             self.sounds[message.soundcomponent] = gate_time
-            -- "play_sound" 메세지를 실제 타겟으로 보냄
-            msg.post(message.soundcomponent, "play_sound", { gain = message.gain })
+            sound.play(message.soundcomponent, { gain = message.gain })
         else
             -- 재생하려는 사운드를 막았음
             print("gated " .. message.soundcomponent)
@@ -137,4 +136,3 @@ msg.post("/sound_gate#script", "play_gated_sound", { soundcomponent = "/sounds#e
 ```
 
 > "play_sound"는 Defold 엔진에 의해 예약된 이름이므로 게이트는 이 메세지를 들을 수 없습니다. 예약된 메세지 이름을 사용하면 예기치 않은 동작이 발생할 수 있습니다.
-