pyxora.wrapper.sfx

 1import pygame
 2
 3class SoundEffect:
 4    _volume = 1.0
 5    def __init__(self, effect:pygame.mixer.Sound, volume:float=1.0) -> None:
 6        """
 7        Initialize a SoundEffect object
 8
 9        Args:
10            effect (pygame.mixer.Sound): The sound effect.
11            volume (float): The volume level of the music.
12        """
13        self._effect = effect
14        self._local_volume = volume
15
16    @property
17    def playing(self) -> bool:
18        """The playing status of the effect."""
19        return bool(self._effect.get_num_channels())
20
21    @property
22    def channels(self) -> int:
23        """The number of channels the effect is playing on."""
24        return self._effect.get_num_channels()
25
26    @property
27    def length(self) -> float:
28        """The length of the sound effect in seconds."""
29        return self._effect.get_length()
30
31    @property
32    def raw(self) -> bytes:
33        """The raw data of the sound effect in byes"""
34        return self._effect.get_raw()
35
36    @property
37    def volume(self) -> float:
38        """The volume of the music (volume * local_volume)."""
39        return self._volume * self._local_volume
40
41    @classmethod
42    def change_volume(cls,value: float) -> None:
43        """Change the volume of all music."""
44        cls._volume = value
45        self._effect.set_volume(cls.volume)
46
47    def change_local_volume(self,value: float) -> None:
48        """Change the volume of the music."""
49        self._local_volume = value
50        self._effect.set_volume(self.volume)
51
52    def play(self,loops:int=-1, maxtime:int=0, fade_ms:int =0) -> None:
53        """
54        Starts the sound effect.
55
56        Parameters:
57            loops (int): Number of times to repeat the sound effect after the first play.
58                        -1 means the sound effect will play once.
59                        0 means indefinitely.
60                        >=1 means play n times.
61
62            maxtime (int): Max Milliseconds to play the sound effect.
63
64            fade_ms (int): Milliseconds to fade in the sound effect.
65        """
66        self._effect.stop() # stop and play a new one
67        self._effect.play(loops+1,maxtime,fade_ms)
68
69    def stop(self) -> None:
70        """
71        Stop the sound effect.
72        """
73        self._effect.stop()
class SoundEffect:
 4class SoundEffect:
 5    _volume = 1.0
 6    def __init__(self, effect:pygame.mixer.Sound, volume:float=1.0) -> None:
 7        """
 8        Initialize a SoundEffect object
 9
10        Args:
11            effect (pygame.mixer.Sound): The sound effect.
12            volume (float): The volume level of the music.
13        """
14        self._effect = effect
15        self._local_volume = volume
16
17    @property
18    def playing(self) -> bool:
19        """The playing status of the effect."""
20        return bool(self._effect.get_num_channels())
21
22    @property
23    def channels(self) -> int:
24        """The number of channels the effect is playing on."""
25        return self._effect.get_num_channels()
26
27    @property
28    def length(self) -> float:
29        """The length of the sound effect in seconds."""
30        return self._effect.get_length()
31
32    @property
33    def raw(self) -> bytes:
34        """The raw data of the sound effect in byes"""
35        return self._effect.get_raw()
36
37    @property
38    def volume(self) -> float:
39        """The volume of the music (volume * local_volume)."""
40        return self._volume * self._local_volume
41
42    @classmethod
43    def change_volume(cls,value: float) -> None:
44        """Change the volume of all music."""
45        cls._volume = value
46        self._effect.set_volume(cls.volume)
47
48    def change_local_volume(self,value: float) -> None:
49        """Change the volume of the music."""
50        self._local_volume = value
51        self._effect.set_volume(self.volume)
52
53    def play(self,loops:int=-1, maxtime:int=0, fade_ms:int =0) -> None:
54        """
55        Starts the sound effect.
56
57        Parameters:
58            loops (int): Number of times to repeat the sound effect after the first play.
59                        -1 means the sound effect will play once.
60                        0 means indefinitely.
61                        >=1 means play n times.
62
63            maxtime (int): Max Milliseconds to play the sound effect.
64
65            fade_ms (int): Milliseconds to fade in the sound effect.
66        """
67        self._effect.stop() # stop and play a new one
68        self._effect.play(loops+1,maxtime,fade_ms)
69
70    def stop(self) -> None:
71        """
72        Stop the sound effect.
73        """
74        self._effect.stop()
SoundEffect(effect: pygame.mixer.Sound, volume: float = 1.0)
 6    def __init__(self, effect:pygame.mixer.Sound, volume:float=1.0) -> None:
 7        """
 8        Initialize a SoundEffect object
 9
10        Args:
11            effect (pygame.mixer.Sound): The sound effect.
12            volume (float): The volume level of the music.
13        """
14        self._effect = effect
15        self._local_volume = volume

Initialize a SoundEffect object

Arguments:
  • effect (pygame.mixer.Sound): The sound effect.
  • volume (float): The volume level of the music.
playing: bool
17    @property
18    def playing(self) -> bool:
19        """The playing status of the effect."""
20        return bool(self._effect.get_num_channels())

The playing status of the effect.

channels: int
22    @property
23    def channels(self) -> int:
24        """The number of channels the effect is playing on."""
25        return self._effect.get_num_channels()

The number of channels the effect is playing on.

length: float
27    @property
28    def length(self) -> float:
29        """The length of the sound effect in seconds."""
30        return self._effect.get_length()

The length of the sound effect in seconds.

raw: bytes
32    @property
33    def raw(self) -> bytes:
34        """The raw data of the sound effect in byes"""
35        return self._effect.get_raw()

The raw data of the sound effect in byes

volume: float
37    @property
38    def volume(self) -> float:
39        """The volume of the music (volume * local_volume)."""
40        return self._volume * self._local_volume

The volume of the music (volume * local_volume).

@classmethod
def change_volume(cls, value: float) -> None:
42    @classmethod
43    def change_volume(cls,value: float) -> None:
44        """Change the volume of all music."""
45        cls._volume = value
46        self._effect.set_volume(cls.volume)

Change the volume of all music.

def change_local_volume(self, value: float) -> None:
48    def change_local_volume(self,value: float) -> None:
49        """Change the volume of the music."""
50        self._local_volume = value
51        self._effect.set_volume(self.volume)

Change the volume of the music.

def play(self, loops: int = -1, maxtime: int = 0, fade_ms: int = 0) -> None:
53    def play(self,loops:int=-1, maxtime:int=0, fade_ms:int =0) -> None:
54        """
55        Starts the sound effect.
56
57        Parameters:
58            loops (int): Number of times to repeat the sound effect after the first play.
59                        -1 means the sound effect will play once.
60                        0 means indefinitely.
61                        >=1 means play n times.
62
63            maxtime (int): Max Milliseconds to play the sound effect.
64
65            fade_ms (int): Milliseconds to fade in the sound effect.
66        """
67        self._effect.stop() # stop and play a new one
68        self._effect.play(loops+1,maxtime,fade_ms)

Starts the sound effect.

Arguments:
  • loops (int): Number of times to repeat the sound effect after the first play. -1 means the sound effect will play once. 0 means indefinitely. >=1 means play n times.
  • maxtime (int): Max Milliseconds to play the sound effect.
  • fade_ms (int): Milliseconds to fade in the sound effect.
def stop(self) -> None:
70    def stop(self) -> None:
71        """
72        Stop the sound effect.
73        """
74        self._effect.stop()

Stop the sound effect.