Main Content

You are here:

Sound Manipulation

Hello and welcome. Today, we will be making this (speakers a neccessity) :

The first things you are going to need for this tutorial are the sounds, which I have thoughtfully uploaded. One of them is the short explosion sound, and the other is the background music (I have used a different sound in the video tutorial). Thanks go to Lacrioso who has some excellent classical pieces on Newgrounds. Once you have them, we can continue.

Before we can do anything, we need to import the sounds. To do this, select File > Import > Import to Library.Browse to one of the files ad press okay. Repeat for the next sound. You should see them appear on the library. Next you need yo lin them, and remember the names you linked them as I named mine explosion and background, so they're the names I will be using in a moment. We start with the bang! sound button (makes sure you create a button):

on(release){
        var mySound = new Sound;

That means we create a new variable, in this case a sound object type variable. From now on our sound will be known as mySound. The next lines introduce us to some new functions, so underneath each I have explained how they work.

     mySound.attachSound("explosion");
        //soundVariable.attachSound("name defined in linkage");
        mySound.start(0,1);
        //soundVariable.start(delay, number of times to loop)
}

The second, start() is, in this case, filled in with the default values. Hence for this one, we could have used mySound.start();. But we didn't, because later we will want to use a different number of loops. That is for the background sound, which you want to loop 99 times (or more if need be). The background button is basically a copy of the bang button, with a couple of details changed:

on(release){
        var mySound = new Sound
        mySound.attachSound("background");
        mySound.start(0,99);
}

There we go. The last part to this tutorial is, in effect, a temporary mute button, that stops all sounds currently playing. The code is quite simple:

on(release){
        stopAllSounds();
}

That is the most simple, effective code for getting some peace, but there are other ways, which we may explore in further tutorials.

Harry.

Comments