3.3 KiB
Executable file
Section 03 - Lesson 16, 17 | Game Over, Sound End Game
Notes
stopping the game
-
create a function that handles all cleanup
-
stop the timer
- drag + CMD and drop Timer to create a reference
- timer.stop
-
set all node children process to false
- Node function
get_childrenwill get them all3 - iterate through them and
set_process(false)
- Node function
-
sound
import pane
-
the scene panel on the upper left has an Import pane
file:../../_share/media/img/albert/section03/S03_L16_E01.png
-
this allows you to see details of items in the filesystem
file:../../_share/media/img/albert/section03/S03_L16_E03.png
changing details of imported items
- make whatever changes you want, e.g. turn on "Loop"
-
then click the Reimport button
file:../../_share/media/img/albert/section03/S03_L16_E04.png
audio nodes
-
Node->Node2D->AudioListener2D
- overrides location sounds are heard from
-
Node->Node2D->AudioStreamPlayer2D
- plays positionnal sound in 2D space
-
Node->AudioStreamPlayer
-
simple audio player
- Playing: plays in the GAME EDITOR
- Autoplay: plays as soon as it is loaded into the scene tree
-
create background music
-
add new Audio node to the scene panel on the Game scene
- use AudioStreamPlayer bc we don't care about position
-
drag the audio file into Audio node->Inspector->AudioStreamPLayer->Stream
file:../../_share/media/img/albert/section03/S03_L16_E05.png
-
you'll be able to see it when it's loaded
file:../../_share/media/img/albert/section03/S03_L16_E06.png
-
- set Autoplay to "ON"
add effects
- use AudioStreamPlayer2D bc it has positioning
- CMD+drag the AudioStreamPlayer2D node to the game.gd script so we can play it
- call the effect when something happens (e.g. a gem hits the panel)
-
find the position of where the even happens "area.position"
audio_stream_player_2d.position = area.position audio_stream_player_2d.play()
add game over sound
- first make sure no other sound such as effects sounds are playing.
-
call "stop()" on all such nodes
audio_stream_player_2d.stop() -
load the game over sounds using "preload"
- CMD+drag the sound file from the filesystem to the game.gd script
- godot will automatically create a constant with the file name
- godot will also set that file to "preload" with the appropriate file path
-
set the
streamproperty ofaudio_stream_player_2dto the preloaded sound and play itaudio_stream_player_2d.stream = EXPLODE audio_stream_player_2d.play() - put all this into a function and add it to the game_over function