Add audio/play_on_event example#23219
Open
zerocukor287 wants to merge 1 commit intobevyengine:mainfrom
Open
Conversation
Contributor
|
This is a nice basic example, it might make sense to also have the minimum amount of setup needed to have text on screen that says "press space to play audio." |
Add an example that demonstrate how to load an audio file and play multiple times on a specific event (pressing space).
Contributor
Author
|
@fallible-algebra I've added a short text to press space. I think the PR is done from my side. |
kfc35
approved these changes
Mar 6, 2026
Contributor
kfc35
left a comment
There was a problem hiding this comment.
Tested the example myself and it works.
Approving, as long as spawning a camera is also included.
| let handle = asset_server.load("sounds/breakout_collision.ogg"); | ||
| commands.insert_resource(SoundEffect(handle)); | ||
|
|
||
| // example instructions |
Contributor
There was a problem hiding this comment.
You also have to spawn a camera before the instructions will appear
Suggested change
| // example instructions | |
| commands.spawn(Camera2d); | |
| // example instructions |
This file contains hidden or 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
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.
Add
audio/play_on_eventexampleObjective
Add an example that demonstrates how to load an audio file and play it multiple times on a specific event (pressing space).
Solution
It is similar to the breakout example, but way shorter. This example loads a sound effect on startup, and on a keyboard event spawns a
AudioPlayerwithDESPAWNmode.Testing