Repeated Sounds

Non-platform specific questions.

Repeated Sounds

Postby peedalein » 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


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");};



Attachments
testsound.zip
(329.32 KiB) Downloaded 55 times
peedalein
 
Posts: 54
Joined: Mon May 17, 2010 2:26 pm
Score: 1 Give a positive score

Re: Repeated Sounds

Postby skydereign » Tue Aug 02, 2011 8:36 am

Well, you'll need a timer of some sort (variable or built in). When you go to play the sound, check the variable, and if it is zero play the sound and set the variable. You can right a wrapper function to do this for you, and just use the view actor's draw to maintain the timers. But this is generally what it would look like.
actor -> Draw Actor -> Script Editor
Code: Select all
sound_timer-=sound_timer>0;
if(sound_timer==0)
{
    //PlaySound2 function call
    sound_timer=30; // for 1 second long sound
}
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest