Controlling emitter

Discussion in 'Programming' started by Architheutis, Apr 16, 2019.

  1. Architheutis

    Architheutis Member

    Joined:
    Nov 9, 2018
    Posts:
    36
    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.
     
  2. obscene

    obscene Member

    Joined:
    Jun 21, 2016
    Posts:
    2,343
    // 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.
     
    Architheutis likes this.
  3. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    337
    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)
    }
    
     
    Architheutis likes this.
  4. Architheutis

    Architheutis Member

    Joined:
    Nov 9, 2018
    Posts:
    36
    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 likes this.
  5. Edwin

    Edwin Member

    Joined:
    Jul 15, 2018
    Posts:
    337
    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)
        }
    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice