GMS 2 Sound Tutorials

Discussion in 'Programming' started by Elgarion, Sep 24, 2019.

  1. Elgarion

    Elgarion Member

    Joined:
    Apr 12, 2018
    Posts:
    44
    Hello dear fellow developers!

    Recently, the clunky sound system I spent days to develop seem to have been quite broken, probably by an update, (or maybe it just collapsed under the weight of my bad practice ^^).

    I just spent some time looking for decent & recent sound tutorials (3D, emiters, general sound handling, etc.). I've got some in youtube, but very incomplete and frustrating (and most of them seemed too basic for my needs); that's all...

    Do you know where I can find any complete ressource, with examples, for the way the sound is handled in GMS 2 ?
     
  2. johnwo

    johnwo Member

    Joined:
    Jun 20, 2016
    Posts:
    239
    When there is a lack tutorials, your best bet is to just read the documentation. It includes examples and explanations.
     
    Elgarion likes this.
  3. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    How about answering your implicit question instead, perhaps... what does your sound system need to do? It might not be that complicated after all... (or it might be, kinda hard to tell unless you tell us what you want to do)
     
    Elgarion likes this.
  4. Elgarion

    Elgarion Member

    Joined:
    Apr 12, 2018
    Posts:
    44
    Thank you for you kind words @Yal . I'm gonna try to fix it by myself using the doc, as @johnwo said. If I'm still not satisfied with my work in a few day I will come back here to seek some help from you and others. It's about distance, sounds that should be heard and are not (and were before some point, which is strange, that's why I think about some GM update, because once settled I didn't touched the sound area).
     
  5. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    3,742
    Oh, in that case I think I know what you wanna do.

    To play a sound, do something like this:

    Code:
    ///sfx_position(sound,x,y)
    var n = audio_play_sound_at(argument0,argument1,argument2,0,VIEW_H*0.5,VIEW_W,1,false,10);
    //use the variable "n" to apply effects like a global volume option here if you want
    return n;
    
    Have your player do this every step:
    Code:
    //Positional audio
    audio_listener_position(x,y,0)
    audio_listener_orientation(x,y,1000,0,-1,0)
    audio_listener_velocity(xspeed,yspeed,0)
    

    This is copypasted from a project I'm working on atm so replace the constants with whatever values work in your project. It's surprisingly easy to use play_sound_at to play the sound at a position in 3D space, the tricky bit is that the listener orientation defaults to upside-down. Also, this was for a 2D project so note that the z coordinate is zero everywhere.
     
    Elgarion likes this.
  6. Elgarion

    Elgarion Member

    Joined:
    Apr 12, 2018
    Posts:
    44
    Thank you @Yal !
    My problem is that I melt some old GMS1 code of mine with some 3D from GMS2, so everything was clumsy.

    I have to clean everything up. Will use your piece of code and modernize my own code.

    Have a nice day !
     
    Last edited: Oct 7, 2019

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