compsci_godot_albert/_subsections/sec03/lesson-16.org

94 lines
3.3 KiB
Org Mode
Raw Normal View History

#+title: Section 03 - Lesson 16, 17 | Game Over, Sound End Game
2024-11-29 06:41:22 +02:00
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
* Links
- [[../../toc.org][TOC - Godot Notes]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070491#announcements][S03:L27.16 - Game Over]]
- [[https://www.udemy.com/course/jumpstart-to-2d-game-development-godot-4-for-beginners/learn/lecture/45070493#announcements][S03:L28.17 - Sound / End of Game]]
* Notes
** stopping the game
1. create a function that handles all cleanup
1. stop the timer
- drag + CMD and drop Timer to create a reference
- timer.stop
2. set all node children process to false
- Node function =get_children= will get them all3
- iterate through them and =set_process(false)=
2024-11-27 00:49:44 +02:00
** sound
*** import pane
- the scene panel on the upper left has an Import pane
#+ATTR_HTML: :width 600px
2024-12-01 01:09:29 +02:00
file:../../_share/media/img/albert/section03/S03_L16_E01.png
2024-11-27 00:49:44 +02:00
- this allows you to see details of items in the filesystem
#+ATTR_HTML: :width 400px
2024-12-01 01:09:29 +02:00
file:../../_share/media/img/albert/section03/S03_L16_E03.png
2024-11-27 00:49:44 +02:00
*** changing details of imported items
1. make whatever changes you want, e.g. turn on "Loop"
2. then click the Reimport button
#+ATTR_HTML: :width 400px
2024-12-01 01:09:29 +02:00
file:../../_share/media/img/albert/section03/S03_L16_E04.png
2024-11-27 00:49:44 +02:00
*** 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
#+ATTR_HTML: :width 600px
2024-12-01 01:09:29 +02:00
file:../../_share/media/img/albert/section03/S03_L16_E05.png
2024-11-27 00:49:44 +02:00
- you'll be able to see it when it's loaded
#+ATTR_HTML: :width 600px
2024-12-01 01:09:29 +02:00
file:../../_share/media/img/albert/section03/S03_L16_E06.png
2024-11-27 00:49:44 +02:00
- 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"
#+BEGIN_SRC gdscript
audio_stream_player_2d.position = area.position
audio_stream_player_2d.play()
#+END_SRC
*** add game over sound
- first make sure no other sound such as effects sounds are playing.
- call "stop()" on all such nodes
#+BEGIN_SRC gdscript
audio_stream_player_2d.stop()
#+END_SRC
- 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 =stream= property of =audio_stream_player_2d= to the preloaded sound and play it
#+BEGIN_SRC gdscript
audio_stream_player_2d.stream = EXPLODE
audio_stream_player_2d.play()
#+END_SRC
2024-12-04 09:50:17 +02:00
- put all this into a function and add it to the game_over function