Repeated Sounds
Posted: Mon Aug 01, 2011 9:54 pm
Greetings,
I have a problem with the sound in GE.
My setup:
I have an event that triggers an actor to appear randomly (on the right or left side of the screen). In the attached example the event has been substitued
by a key down event.
Once the actor appeared and a 30 frames countdown passed, the actor moves to the other side of the screen. During the movement I want GE to repeat a sound sample for the duration of the movement. The sound sample is app. 1 second. The speed of the movement varies in the actual game.
My current method uses the DrawActor to play the sound once the conditions are met.
The problem:
For each single frame GE starts to play the sound again and I end up having a total cacophony (several repetitions in 1 second).
I would like GE to play the sound till the end and only then repeat it.
I noticed that when I set the maximum number of simultaneous sounds in the Game Properties to 1, GE does actually play the sound till the very end and only then repeats it. Once I change the number to >1 I get again this cacophony/echo thing.
Is there a good way to repeat sounds not using timers (as the duration of the movement varies)?
Thanks
I have a problem with the sound in GE.
My setup:
I have an event that triggers an actor to appear randomly (on the right or left side of the screen). In the attached example the event has been substitued
by a key down event.
Once the actor appeared and a 30 frames countdown passed, the actor moves to the other side of the screen. During the movement I want GE to repeat a sound sample for the duration of the movement. The sound sample is app. 1 second. The speed of the movement varies in the actual game.
My current method uses the DrawActor to play the sound once the conditions are met.
The problem:
For each single frame GE starts to play the sound again and I end up having a total cacophony (several repetitions in 1 second).
I would like GE to play the sound till the end and only then repeat it.
I noticed that when I set the maximum number of simultaneous sounds in the Game Properties to 1, GE does actually play the sound till the very end and only then repeats it. Once I change the number to >1 I get again this cacophony/echo thing.
Is there a good way to repeat sounds not using timers (as the duration of the movement varies)?
Thanks
- Code: Select all
//plays sound
if(ActorMove!=0){PlaySound2("data/crowd.wav", 1.000000, 1, 0.000000);};
// counts the frames, used as a method to measure time and trigger stuff
fcount = fcount + 1;
// resets counter to 0 once the button is pressed
if (PressedButton == 1) {fcount=0;PressedButton=2;};
// Once button is pressed it places the actor on the left side (if ActorSide is 1)
if(ActorSide == 1 && fcount == 1 && PressedButton == 2) {MainActor.x = -450;MainActor.y = 240;};
// if actor is placed in the left and frame counter reaches 30 it moves the actor from the left to the right side
if(MainActor.x == -450 && fcount == 30) {ActorMove = 1;};
// if actor is placed in the left and frame counter reaches 30 it moves the actor from the left to the right side
if(MainActor.x == 500 && fcount == 30) {ActorMove = 2;};
// Once button is pressed it places the actor on the right side (if ActorSide is 0)
if(ActorSide == 0 && fcount == 1 && PressedButton == 2) {MainActor.x = 500;MainActor.y = 240;};
// substitutes GE's MoveTo, moves Actor to right
if (ActorMove == 1) {if (x < 500) { x = x + ActorSpeed;};};
// substitutes GE's MoveTo, moves Actor to left
if (ActorMove == 2) {if (x > -450) { x = x - ActorSpeed;};};
// resets random side for actor, resets PressedButton and sets ActorMove to 0 (-> no movement)
if(fcount == 150 && PressedButton == 2) {ActorSide = rand(2); PressedButton=0; DestroyActor("MainActor");};