- 出道即巅峰,先做个盈利千万的小项目
- 新建 Godot 项目
- Godot 界面介绍
- FlappyBird:1.Hello World
- FlappyBird:2.坠落吧,小鸟
- FlappyBird:3.在哪坠落就在哪飞起来
- FlappyBird:4. 无限地面
- FlappyBird:4.1 无限地面之 Godot 青年 (AnimationPlayer) 版
- FlappyBird:4.2 无限地面之普通青年版
- FlappyBird:4.3 无限地面之文艺青年(shader) 版
- FlappyBird:5.1 无尽水管子滚滚来(一)
- Godot Engine:5 种碰撞体以及 RigidBody 的 4 种模式
- Godot Engine:碰撞和碰撞检测的简单实例(RigidBody2D 与 Area2D 碰撞)
- Godot Engine:碰撞和碰撞检测的简单实例(RigidBody2D 与 StaticBody2D 碰撞)
- FlappyBird:5.2 无尽水管子滚滚来(二)
- Godot Engine:Timer 节点使用范例
- FlappyBird:6 来点 MUSIC(音效系统)
- Godot Engine:用自动加载(AutoLoad) 实现单例模式(Singleton Pattern)
- FlappyBird:7 心里有数(计分系统)
- Godot Engine:本地数据存取的帮助类(加密/非加密)
- FlappyBird:8 让数据说话(显示分数)
- Godot Engine:如何使用外部字体和 Label 节点制作一个计时器
- FlappyBird:9.1 天下没有不 OVER 的 GAME(上)
- Godot Engine:两行代码实现观察者模式(Observer Pattern),就问你服不服?
- FlappyBird:9.2 天下没有不 OVER 的 GAME(下)
- FlappyBird:10 大不了从头再来(新局启动)
- Godot Engine:用 Call Method Track(方法回调轨道)实现动画回调
- FlappyBird:11 番外篇:罗永浩都抖音了,要不咱们也抖一抖?(屏幕震动)
- Godot Engine:屏幕振动效果的实现
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
FlappyBird:6 来点 MUSIC(音效系统)
本章节效果图
本节增加的是音效,请大家结合下图脑补
步骤
1. 确认音频资源
2. 新建 AudioManager 场景
场景根节点“AudioManager”的类型为 Node
类型
3. 配置音频资源
注意: 共有 3 个以"AudioStreamPlayer"开头的节点:
AudioStreamPlayer
:位置无关的音频流播放器(2D/3D 通用)AudioStreamPlayer2D
位置相关的音频流播放器 2DAudioStreamPlayer3D
位置相关的音频流播放器 3D
本例中我们为每个音频资源,添加一个位置无关版本的音频流播放器
"AudioManager"配置完毕的样子
4. 添加脚本
5. 保存"AudioManager"场景
extends Node
func play(name : String):
var sfx = find_node(name)
if sfx is AudioStreamPlayer:
sfx.play()
6. 将"AudioManager"场景设置为单例场景
关于使用自动加载(AutoLoad)实现单例场景的详细介绍,请见 《
Godot Engine:用自动加载(AutoLoad) 实现单例模式(Singleton)
》
7. 调用"AudioManager"
# Bird.gd
extends RigidBody2D
func _ready():
connect("body_entered",self,"on_body_entered")
func _physics_process(delta):
if Input.is_mouse_button_pressed(1):
AudioManager.play("sfx_swooshing")#音效
linear_velocity = Vector2.UP*500
angular_velocity = -3.0
if rotation_degrees < -30:
rotation_degrees = -30
angular_velocity = 0
if linear_velocity.y > 0.0:
angular_velocity = 1.5
func on_body_entered(_body):
if _body is StaticBody2D:
AudioManager.play("sfx_hit")#音效
print("Die.....")
#ScoreArea.gd
extends Area2D
func _ready():
connect("body_exited",self,"_on_body_exited")
func _on_body_exited(_body):
if _body.name == "Bird":
AudioManager.play("sfx_point")#音效
print("得分!!!!")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论