Using sound in the game will do a lot in the game experience and using sounds in Godot is quite simple.
Use the Import > Audio sample menu. You will get a window that let you define the file you want to import, the path you want to store the new resource and also the options applied to the import process. Most of these options aim to increase the game efficiency, generally opposed to sound quality as we’ll see later.
// img
When done, a new smp file id added to the project filesystem.
// img
If you are looking for sample and sound library, have a look at http://www.freesound.org/, http://opengameart.org/art-search-advanced?keys=&field_art_type_tid%5B%5D=13 or http://opengameart.org/art-search-advanced?keys=&field_art_type_tid%5B%5D=12When you want to use your sounds in your projects, you’ll need to make a difference between sound effects, and audio streams, like background music.
In the case of audio streams, you will need a streamPlayer node.
// img
If you want to provide the sound with a script, just attach a script to the node and add this :
extends StreamPlayer
func _ready():
self.play()
This will certainly be the best choice if you want the stream be related to a game option. If you want to change the stream during the game you can load it
song2 = load("song2.ogg"
)
and then set it with your player’s set_stream() method before playing it
set_stream(song2)
In the case of sound effect, you will have more things to set. You will have choice between samplePlayer / samplePlayer2D / samplePlayer3D nodes. The first is the most basic, but the two others give stereo effects based on sound position on scene. For those sounds, it’s a good choice to use .wav files.
You will then need to attach the sound to an event in a script file that will play the sound :
get_node("sound").play("hit")
Here, sound is the name of the node and hit the name of the sound resource as defined in sampleLibrary.
If you need to play several sounds at once, set the Config / Voices properties in the Inspector so that each sound owns its one.
If you want to deal more with the sounds especially sets the volume, you will have to attribute your play event to a variable, and then use this variable as the first parameter of the set_volume
method.
var sound = get_node("sound")
var id = sound.play("hit")
id.set_volume(id, 0.5)
But using sound isn’t as simple is could appear. You may have seen that we told «import the .wav file». What’s this antic format ?! In fact, most of the sounds used nowadays are compressed sounds, like mp3 or ogg. That’s why there are interesting for online music : downloading them is fast and you don’t need a huge storage to keep them. Here we could say : «cool ! my game will be lighter without doing any efforts».
Unfortunately, compress means on the other hand uncompress. So, using compressed formats in the game will result in a need to uncompress at runtime, before playing game. In practice this will increase the amount of calculation done by the engine and slow down the game. Remember that the game engine needs to maintain plenty of other calculations and that it is never a good idea to count on the engine effort without evaluation.
For sound effects, it’s important the sound plays as quickly as possible to avoid delay. Use .wav.
For audio streams, there is no need to have the whole file in memory to be played and delay won’t be a problem because those sounds are not related to game interaction. In this case OGG or MPC will be good choice for Godot. Files can be convert with audacity if needed.
We can say the same about sound creation. Adding effects to sounds, like reverb, will enlarge the file size and in the same time the effort need to render. It’s not a bad idea to begin with simple sounds, and, when the game production reaches the end, see if there is opportunity for better resources. In that purpose, sfx artists should be aware to always keep the source files to update the game resources from a good quality original. To avoid, problem involved by such effects, Godot includes a reverb generator adapted to game rendering, that can be setup with a four-step range.
An other point in which savings can be done is trimming. In many sounds there will be a portion of silence at the beginning and at the end. The problem of the sounds is that they will be delay when played. Cutting the sound so that only the significant part in kept will make things clearer when delay will need to be set. This will eventually be a question of settings or scripting in the engine and there won’t be no need to edit the sound for other results.
It will be a designer choice to know when to put the effort in Godot effects and when it should be done with a sound editor.
Some other saving can be done in quality. Most of time, sound are stereo with a high sampling rate such as 96khz. In fact, using 44khz mono will drastically reduce size file memory efforts. Generally, for most use cases, the difference won’t be audible to users. So it would be a good choice to downsample sounds if possible.
Sound artist will often be disappointed by this approach, because it’s an opposite position that they will have learned. They’ll feel like limited and that they can’t give the best. Anyway, it’s important to keep in mind that a game is a whole and that visual artist would also like to have high-resolution images, 3D artists high poly meshes, and so on. From this point of view the game is still a compromise, the most important being fluency and playing comfort.
Il y a une erreur de communication avec le serveur Booktype. Nous ne savons pas actuellement où est le problème.
Vous devriez rafraîchir la page.