Skip to content

Commit 1793359

Browse files
nahaharoHyunwook HaSimonDarksideJ
authored
Minor fixes for the AudioController.Update() at 2D Tutorial (#89)
* Add index++ to 2D Tutorial's AudioController.Update() * Update Code according to MonoGame/docs.monogame.github.io#148 --------- Co-authored-by: Hyunwook Ha <hyunwookha@gmail.com> Co-authored-by: Simon (Darkside) Jackson <darkside@zenithmoon.com>
1 parent 5542d1f commit 1793359

File tree

13 files changed

+105
-105
lines changed

13 files changed

+105
-105
lines changed

Tutorials/learn-monogame-2d/src/15-Audio-Controller/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/16-Working-With-SpriteFonts/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/17-Scenes/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/18-Texture-Wrapping/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/19-User-Interface-Fundamentals/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/20-Implementing-UI-With-Gum/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/21-Customizing-Gum-UI/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/22-Snake-Game-Mechanics/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ public AudioController()
9797

9898
/// <summary>
9999
/// Updates this audio controller
100-
/// </summary>
100+
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/23-Completing-The-Game/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

Tutorials/learn-monogame-2d/src/24-Shaders/MonoGameLibrary/Audio/AudioController.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ public AudioController()
100100
/// </summary>
101101
public void Update()
102102
{
103-
int index = 0;
104-
105-
while (index < _activeSoundEffectInstances.Count)
103+
for (int i = _activeSoundEffectInstances.Count - 1; i >= 0; i--)
106104
{
107-
SoundEffectInstance instance = _activeSoundEffectInstances[index];
105+
SoundEffectInstance instance = _activeSoundEffectInstances[i];
108106

109-
if (instance.State == SoundState.Stopped && !instance.IsDisposed)
107+
if (instance.State == SoundState.Stopped)
110108
{
111-
instance.Dispose();
109+
if (!instance.IsDisposed)
110+
{
111+
instance.Dispose();
112+
}
113+
_activeSoundEffectInstances.RemoveAt(i);
112114
}
113-
114-
_activeSoundEffectInstances.RemoveAt(index);
115115
}
116116
}
117117

0 commit comments

Comments
 (0)