-
Notifications
You must be signed in to change notification settings - Fork 60
Fix for AudioController.Update() at 2d game tutorial. #148
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
Conversation
I think there is still an issue with this loop. If you remove an element from the list, you shouldn't increase the index, otherwise you would skip an element.
Alternatively, you can iterate backward to simplify this and have a predictable loop:
|
I think backward iteration is a better solution. public void Update()
{
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
{
SoundEffectInstance instance = _activeSoundEffectInstances[i];
if (instance.State == SoundState.Stopped)
{
if (!instance.IsDisposed)
{
instance.Dispose();
}
_activeSoundEffectInstances.RemoveAt(i);
}
}
} |
Yes, this version would be more preferable, please update @nahaharo |
* fix for AudioController.Update() at 2d game tutorial. * update code with backward iteration --------- Co-authored-by: Hyunwook Ha <[email protected]>
* Add index++ to 2D Tutorial's AudioController.Update() * Update Code according to MonoGame/docs.monogame.github.io#148 --------- Co-authored-by: Hyunwook Ha <[email protected]> Co-authored-by: Simon (Darkside) Jackson <[email protected]>
* Updated samples page (MonoGame#149) * Add samples section to main docs links * Updated samples page * Update index.md (MonoGame#147) corrected spelling on line 20 * Update index.md (MonoGame#146) Lines 211 - 214 (Key changes made): There was an update needed to this. Previous stated the file name was "04B_11.ttf" and the size was "32". The update is to match the snippet and the download. * Update textureregion.cs (MonoGame#153) Fix the comments for the constructor * typo (MonoGame#152) * Update WhatIs_Sprite.md (MonoGame#151) Corrected coordinates in the overview section * removed accidental backtick in CLI command (MonoGame#150) * "the" (MonoGame#154) * Update core.cs * Update tilemap.cs * Update core.cs * Update core.cs * Update core.cs * Update index.md * Fix for AudioController.Update() at 2d game tutorial. (MonoGame#148) * fix for AudioController.Update() at 2d game tutorial. * update code with backward iteration --------- Co-authored-by: Hyunwook Ha <[email protected]> * fix(docs): correct typos and improve consistency across articles (MonoGame#145) * Clarify distance labels in circle collision explanation - Added missing word "circles" in description of 'a' - Reworded all three distance descriptions for clarity and consistency * fix(title scene draw): remove unused color assignment to dropShadowColor * fix(title scene draw): add missing comment above dropShadowColor assignment * refactor: fix typo in textureatlas.cs filename * fix(docs): correct typos and improve wording across documentation * (Fix)Removed < > from xref links and set unordered list to ordered list --------- Co-authored-by: Simon (Darkside) Jackson <[email protected]> * Update Roadmap - Resolves MonoGame#137 * Add Maui instructions to "Getting Started guide" and add image - resolves MonoGame#157 * Fix formatting of Tip Admonition (MonoGame#159) * Changes to satisfy #225 (MonoGame#156) * Changes to satisfy #226 * Remove create as it moved to the main site * Fix footer to match * Update links for Bsky and mastodon * Revert MonoGame checkout to 3.8.4 * fix spelling mistake in the ContentManager Methods section of chapter 5 bulding 2d games tutorial (MonoGame#160) * working * Remove exiting from Game1 class and make ExitOnEscape true by default in the core class (MonoGame#163) * Update to remove the usage of the word "objects" which can be confused for OOP (MonoGame#162) * Add info about security and protection (MonoGame#161) * material class * debug ui * working * Gum styling update 2025 8 (MonoGame#164) * Updated styling docs to use ButtonVisual Updated using statements to match new gum namespace * Fixed usings * Upped NuGet versions for MonoGame Docs * Oops forgot this using statement. * Upped version number * Addressed feedback from AristurtleDev * Updated Cartblanch's Samples links and text. * color swap mostly complete * vertex shaders * Fix typo with iOS build instructions (MonoGame#167) * Fix minor Markdown error in CH 21 of the 2D game tutorial (MonoGame#168) * getting started on lighting * in progress * finishing draft of lighitng chapter * shadow stuff * before stencil * mostly done * stencil shadows * zug zug * remove old name * rename folder, update toc, and gif support * metadata * typos * links and callouts * hlsl highlighting support * fixing indentation --------- Co-authored-by: Simon (Darkside) Jackson <[email protected]> Co-authored-by: Mckeehan <[email protected]> Co-authored-by: jani-r <[email protected]> Co-authored-by: bo <[email protected]> Co-authored-by: Quaspen <[email protected]> Co-authored-by: Hyunwook Ha <[email protected]> Co-authored-by: Hyunwook Ha <[email protected]> Co-authored-by: Quest <[email protected]> Co-authored-by: Christopher Whitley <[email protected]> Co-authored-by: Sean Buchas <[email protected]> Co-authored-by: Victor Chelaru <[email protected]> Co-authored-by: Dominique Louis <[email protected]> Co-authored-by: buymyhubs <[email protected]> Co-authored-by: alfuwu <[email protected]>
Fix for the MonoGame/MonoGame#8851
This code fixed two things in AudiroController.Update() at 2D game tutorial.