-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
block_code/picker: Store the AudioStreamPlayer in the VAR_DICT #61
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
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
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! 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) |
wjt
approved these changes
Jun 20, 2024
There was a problem hiding this 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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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