compsci_godot_albert/_subsections/sec03/lesson-16.org
2024-11-27 00:49:44 +02:00

3.4 KiB

Section 03 - Lesson 16, 17 | Game Over, Sound End 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)

sound

import pane

  • the scene panel on the upper left has an Import pane

    file:../../../_share/media/albert/img/section03/S03_L16_E01.png

  • this allows you to see details of items in the filesystem

    file:../../../_share/media/albert/img/section03/S03_L16_E03.png

changing details of imported items

  1. make whatever changes you want, e.g. turn on "Loop"
  2. then click the Reimport button

    file:../../../_share/media/albert/img/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/albert/img/section03/S03_L16_E05.png

    • you'll be able to see it when it's loaded

      file:../../../_share/media/albert/img/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 stream property of audio_stream_player_2d to the preloaded sound and play it

    audio_stream_player_2d.stream = EXPLODE
    audio_stream_player_2d.play()
  • put all this into a function and add it to the game_over function