Share [Tạo 2D Platformer Game với Godot] Phần 28: Thêm âm thanh giao diện

Âm thanh ** Cách thêm âm thanh vào trò chơi trong động cơ Godot **

Trong hướng dẫn này, tôi sẽ chỉ cho bạn cách thêm âm thanh vào trò chơi trong động cơ Godot.Chúng tôi sẽ sử dụng thư viện ** Kenney ** để có được âm thanh.

## Nhận âm thanh

1. Mở cửa sổ ** Thư viện tài sản **.
2. Tìm kiếm ** Kenney **.
3. Nhấp vào nút ** Tải xuống ** để tải xuống âm thanh.
4. Nhấp vào nút ** Cài đặt ** để cài đặt âm thanh.

## Thêm âm thanh vào trò chơi

1. Tạo một nút ** mới ** và thêm nút ** audiostreamplayer2d ** vào nó.
2

## chơi âm thanh

1. Trong tập lệnh ** ** của nút ** ** mà bạn muốn phát âm thanh, hãy thêm mã sau:

`` `
func _on_pression ():
$ AudiosTreamPlayer2d.play ()
`` `

Mã này sẽ phát âm thanh khi nhấn nút ** **.

## Bản tóm tắt

Trong hướng dẫn này, tôi đã chỉ cho bạn cách thêm âm thanh vào trò chơi trong động cơ Godot.Tôi hy vọng bạn tìm thấy hướng dẫn này hữu ích.

** Tags: ** Godot, Game, Sound
=======================================
Sounds **How to add sound to the game in Godot Engine**

In this tutorial, I will show you how to add sound to the game in Godot Engine. We will be using the **Kenney Assets** library to get the sounds.

## Get the sounds

1. Open the **Asset Library** window.
2. Search for **Kenney**.
3. Click the **Download** button to download the sounds.
4. Click the **Install** button to install the sounds.

## Add the sounds to the game

1. Create a new **Node** and add the **AudioStreamPlayer2D** node to it.
2. Drag the sounds from the **Addons** folder into the **Stream** property of the **AudioStreamPlayer2D** node.

## Play the sounds

1. In the **script** of the **Node** that you want to play the sound, add the following code:

```
func _on_pressed():
$AudioStreamPlayer2D.play()
```

This code will play the sound when the **Node** is pressed.

## Summary

In this tutorial, I showed you how to add sound to the game in Godot Engine. I hope you found this tutorial helpful.

**Tags:** Godot, Game, Sound
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top