Skip to content

Conversation

@starnight
Copy link
Contributor

@starnight starnight commented Jun 20, 2024

The new generated AudioStreamPlayer was held by a local variable, then added as a child of the node originally.

It is okay for only one AudioStreamPlayer in the node. However, some nodes may have mulitiple AudioStreamPlayers, then the local variable from the code blocks will be conflicted, due to the same variable name.

Therefore, store the AudioStreamPlayer into the node's global VAR_DICT with a key passed from the parameter "name" directly. This also avoids searching in the node tree.

https://phabricator.endlessm.com/T35501

The new generated AudioStreamPlayer was held by a local variable, then
added as a child of the node originally.

It is okay for only one AudioStreamPlayer in the node. However, some
nodes may have mulitiple AudioStreamPlayers, then the local variable
from the code blocks will be conflicted, due to the same variable name.

Therefore, store the AudioStreamPlayer into the node's global VAR_DICT
with a key passed from the parameter "name" directly. This also avoids
searching in the node tree.

https://phabricator.endlessm.com/T35501
@starnight starnight requested review from manuq, wjt and wnbaum June 20, 2024 04:36
Make the ball node load paddle hit and wall hit audio. Then, play the
AudioStream when the ball hits a paddle, or a wall.

https://phabricator.endlessm.com/T35501
Drop unused WallAudioStreamPlayer and PaddleAudioStreamPlayer. They are
replaced with the Block Code's sound blocks.

Also, disconnect the orphan _on_body_entered callback. The body_entered
signal will be caught by Block Code's "On body entered" block.

https://phabricator.endlessm.com/T35501
@starnight
Copy link
Contributor Author

I also add the sound blocks to the ball node! It plays paddle_hit and wall_hit audio when hits a paddle and a wall!

image

extends RigidBody2D

var VAR_DICT := {}

func _ready():
	VAR_DICT['paddle_hit'] = AudioStreamPlayer.new()
	VAR_DICT['paddle_hit'].name = 'paddle_hit'
	VAR_DICT['paddle_hit'].set_stream(load('res://pong_game/paddle_hit.ogg'))
	add_child(VAR_DICT['paddle_hit'])
	VAR_DICT['wall_hit'] = AudioStreamPlayer.new()
	VAR_DICT['wall_hit'].name = 'wall_hit'
	VAR_DICT['wall_hit'].set_stream(load('res://pong_game/wall_hit.ogg'))
	add_child(VAR_DICT['wall_hit'])

func _on_body_entered(_body: Node):
	var body: NodePath = _body.get_path()
	if get_node(body).is_in_group('paddles'):
		VAR_DICT['paddle_hit'].volume_db = 0.0
		VAR_DICT['paddle_hit'].pitch_scale = 1.0
		VAR_DICT['paddle_hit'].play()
	if get_node(body).is_in_group('walls'):
		VAR_DICT['wall_hit'].volume_db = 0.0
		VAR_DICT['wall_hit'].pitch_scale = 1.0
		VAR_DICT['wall_hit'].play()

func _init():
	body_entered.connect(_on_body_entered)

Copy link
Member

@wjt wjt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broadly looks good, 1 question.

@wjt wjt merged commit 850d0ab into main Jun 20, 2024
@wjt wjt deleted the store-audiostream-in-var_dict branch June 20, 2024 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants