Jypeli
9
The simple game programming library
Sound.cs
Siirry tämän tiedoston dokumentaatioon.
1
using
Microsoft
.
Xna
.
Framework
.Audio;
2
using
System
;
3
4
namespace
Jypeli
5
{
6
public
class
Sound
7
{
8
SoundEffectInstance
effectInstance
;
9
10
static
double
Clamp
(
double
value,
double
min,
double
max )
11
{
12
return
( value < min ) ? ( min ) : ( ( value > max ) ? ( max ) : ( value ) );
13
}
14
18
public
bool
IsLooped
19
{
20
get
{
return
effectInstance
.IsLooped; }
21
set
{
effectInstance
.IsLooped = value; }
22
}
23
31
public
double
Pan
32
{
33
get
{
return
effectInstance
.Pan; }
34
set
{
effectInstance
.Pan = (float)
Clamp
( value, -1.0, 1.0 ); }
35
}
36
40
public
double
Volume
41
{
42
get
{
return
effectInstance
.Volume; }
43
set
{
effectInstance
.Volume = (float)
Clamp
( value, 0.0, 1.0 ); }
44
}
45
52
public
double
Pitch
53
{
54
get
{
return
effectInstance
.Pitch; }
55
set
{
effectInstance
.Pitch = (float)
Clamp
( value, -1.0, 1.0 ); }
56
}
57
58
internal
Sound
( SoundEffectInstance s )
59
{
60
effectInstance
= s;
61
}
62
63
public
void
Play
(
int
retries = 3 )
64
{
65
try
66
{
67
effectInstance
.Play();
68
}
69
#if !WINDOWS_STOREAPP
70
catch
( NullReferenceException )
71
{
72
Console.Error.WriteLine(
"Null reference exception trying to play a sound, disabling audio"
);
73
Game
.
DisableAudio
();
74
}
75
#endif
76
catch
( InvalidOperationException )
77
{
78
// Workaround: Sometimes on Android an InvalidOperationException is thrown when playing a sound
79
// Trying again seems to work; if not, no sound is better than crashing the game
80
if
( retries > 0 )
81
Play
( retries - 1 );
82
}
83
}
84
85
public
void
Resume
()
86
{
87
effectInstance
.Resume();
88
}
89
90
public
void
Stop
()
91
{
92
effectInstance
.Stop();
93
}
94
95
public
void
Pause
()
96
{
97
effectInstance
.Pause();
98
}
99
}
100
}
Jypeli.Sound.Sound
Sound(SoundEffectInstance s)
Definition:
Sound.cs:58
Microsoft.Xna
Definition:
JypeliContentManager.cs:6
Jypeli.Sound.Resume
void Resume()
Definition:
Sound.cs:85
Jypeli.Sound.Pause
void Pause()
Definition:
Sound.cs:95
Jypeli
Definition:
Automobile.cs:5
Jypeli.Sound.Volume
double Volume
Äänenvoimakkuus välillä 0.0 - 1.0.
Definition:
Sound.cs:41
Microsoft
Definition:
JypeliContentManager.cs:6
Jypeli.Sound
Definition:
Sound.cs:7
Microsoft.Xna.Framework
Definition:
JypeliContentManager.cs:6
Jypeli.Sound.effectInstance
SoundEffectInstance effectInstance
Definition:
Sound.cs:8
Jypeli.Sound.Pan
double Pan
Äänen kuuluminen vasemmasta ja oikeasta kaiuttimesta. Arvot vaihtelevat välillä -1....
Definition:
Sound.cs:32
Jypeli.Sound.Clamp
static double Clamp(double value, double min, double max)
Definition:
Sound.cs:10
Jypeli.Sound.Stop
void Stop()
Definition:
Sound.cs:90
Jypeli.Sound.IsLooped
bool IsLooped
Jos true, ääntä soitetaan toistuvasti.
Definition:
Sound.cs:19
Jypeli.Game.DisableAudio
static void DisableAudio()
Definition:
Game.cs:171
System
Definition:
CFFauxAttributes.cs:29
Jypeli.Sound.Pitch
double Pitch
Äänenkorkeus välillä -1.0 - 1.0.
Definition:
Sound.cs:53
Jypeli.Sound.Play
void Play(int retries=3)
Definition:
Sound.cs:63
Jypeli.Game
Definition:
Content.cs:46
Jypeli
Sound
Sound.cs
Generoinut projektille Jypeli Sat Oct 17 2020 19:03:16
1.8.20