[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] questions on pygame.mixer and pygame.mixer.music modules
oops! There is no fadein, just fadeout.
Petes idea of using timers for it is good :)
http://www.pygame.org/docs/ref/pygame_time.html#set_timer
Below is some example code.
Cheers,
import pygame
from pygame.locals import *
FADEIN = USEREVENT + 1
def main ():
volume = 0.0
pygame.init()
screen = pygame.display.set_mode ( ( 10, 10 ) )
pygame.time.set_timer ( FADEIN, 2000 )
pygame.mixer.music.set_volume(volume)
pygame.mixer.music.load("your_music.ogg")
pygame.mixer.music.play()
clock = pygame.time.Clock ()
while True:
pygame.display.update ()
clock.tick ( 20 )
event = pygame.event.wait ()
if event.type == FADEIN:
volume += 0.1
if volume > 1.0:
volume = 1.0
pygame.mixer.music.set_volume(volume)
print volume
elif event.type is MOUSEBUTTONDOWN:
return
elif event.type is QUIT:
return
elif event.type is KEYDOWN and event.key == K_ESCAPE:
return
if __name__ == "__main__":
main()
On 9/13/05, Srinath Avadhanula <srinathava@xxxxxxxxx> wrote:
> Thanks for the replies.
>
> On 9/12/05, Pete Shinners <pete@xxxxxxxxxxxx> wrote:
> > On Mon, 2005-09-12 at 16:57 -0700, Srinath Avadhanula wrote:
> > > 1. Is it possible to "fade-in" a music piece?
> >
> > You'll probably just want to do this with a ramp of set_volume calls. If
> > your app is sleeping on the event queue with pygame.event.wait(), you
> > could start a timer event every second and turn the volume up a little
> > more each time.
>
> I am wondering if there is some documentation which I am missing. Rene
> mentioned fadein, but I cannot see such a function mentioned on:
>
> http://www.pygame.org/docs/ref/pygame_mixer.html
>
> Also, you mention that the SDL library supports doubling and halving
> the frequency... I am very new to SDL. Could you tell me how to do
> this via pygame?
>
> Thanks,
> Srinath
>
> --
> Srinath Avadhanula
> Ph.D candidate, University of California, Berkeley
>