Controlling emitter

Hi developers. :)

I recently solved the problem with playing sounds, coming from enemies = sound direction,
where and how distant the enemy is from the player. Now I want the same effect with moving
enemies.

For example:
I created a patrolling knight with rusty amour. That makes sounds with every step he does.
To "taking the sound with him" (the closer he comes to the player, the louder the noise can be
heard). The sound must move with the x- and y position of the enemy.

I`ve found out, yet, that can be solved by the emitter.
I`ve set in the creation code of the player idle a global emitter ("fxEmitter").
And I`ve put that code to the step of the rusty knight:

Code:
// Here is the site, where the part has to come, to control the FX-emitter

audio_play_sound_on(effectEmitter,au_WarriorWalk01,false,2)
audio_emitter_position(effectEmitter,x,y,0)
As you can see, I wrote a remark line above the emitter activation.
When I play that example, I can hear the sound come and go, depending from
enemies position, if he comes or if he goes away.

But the problem is:
The rusty sound is started 60 times per seconds, a rapidfire of that sound.
:-(

How can I tell gml, just restart playing the audio, after it is ready with playing that sound (1 Second)?
I hope I could explain myself as good as possible!?

Thankful for every hint of you.
Archie.
 

obscene

Member
// Create
snd_walk=noone;

// Step
if !audio_is_playing(snd_walk) snd_walk=audio_play_sound_on(effectEmitter,au_WarriorWalk01,false,2);

You might also consider just triggering the sound on a certain frame of your animation using image_index.
 

Edwin

Member
Hi developers. :)

I recently solved the problem with playing sounds, coming from enemies = sound direction,
where and how distant the enemy is from the player. Now I want the same effect with moving
enemies.

For example:
I created a patrolling knight with rusty amour. That makes sounds with every step he does.
To "taking the sound with him" (the closer he comes to the player, the louder the noise can be
heard). The sound must move with the x- and y position of the enemy.

I`ve found out, yet, that can be solved by the emitter.
I`ve set in the creation code of the player idle a global emitter ("fxEmitter").
And I`ve put that code to the step of the rusty knight:

Code:
// Here is the site, where the part has to come, to control the FX-emitter

audio_play_sound_on(effectEmitter,au_WarriorWalk01,false,2)
audio_emitter_position(effectEmitter,x,y,0)
As you can see, I wrote a remark line above the emitter activation.
When I play that example, I can hear the sound come and go, depending from
enemies position, if he comes or if he goes away.

But the problem is:
The rusty sound is started 60 times per seconds, a rapidfire of that sound.
:-(

How can I tell gml, just restart playing the audio, after it is ready with playing that sound (1 Second)?
I hope I could explain myself as good as possible!?

Thankful for every hint of you.
Archie.
Create an alarm when your Warrior is walking then in alarm event check if he is walking then play the sound.

Like this:
Step Event:
Code:
// If Warrior is walking (hspeed or vspeed arent equal to 0) then
if (hspeed <> 0 || vspeed <> 0) {
    // Play the sound 1/2 seconds.
    alarm[0] = room_speed/2;
}
Alarm 0:
Code:
// Check if he's walking again:
if (hspeed <> 0 || vspeed <> 0) {
    // Play the stepping sound
    audio_play_sound_on(effectEmitter,au_WarriorWalk01,false,2)
    audio_emitter_position(effectEmitter,x,y,0)
}
 
Thank you guys, for giving me these hints!

@obscene: I often used image_index-triggering methods. That works fine - less is more.
But I decided to make it with the first suggestion you made. I think, it´s more elegant.
And I want to become an expert one day ;-) And I want to understand EVERYTHING!
That´s why I like to get my information here, because there are so many bright brains
here, whiches give my many examples for the implemention. :)

@Edwin: That works "extremely excellent" ;-) :) Thank you, for that alternative.
I could use it in another parts of my game coding.

Have a nice and successful day.
Archie.
 

Edwin

Member
Thank you guys, for giving me these hints!

@obscene: I often used image_index-triggering methods. That works fine - less is more.
But I decided to make it with the first suggestion you made. I think, it´s more elegant.
And I want to become an expert one day ;-) And I want to understand EVERYTHING!
That´s why I like to get my information here, because there are so many bright brains
here, whiches give my many examples for the implemention. :)

@Edwin: That works "extremely excellent" ;-) :) Thank you, for that alternative.
I could use it in another parts of my game coding.

Have a nice and successful day.
Archie.
Another alternative is creating a ticking variable and using it with mod expression.

Like this:
Create event:
Code:
tick = 0;
Step event:
Code:
tick ++;

if (hspeed <> 0 || vspeed <> 0)
{
    if ((tick % (room_speed/2)) == 0)
    {
        audio_play_sound_on(effectEmitter,au_WarriorWalk01,false,2)
        audio_emitter_position(effectEmitter,x,y,0)
    }
}
 
Top