130,221

Views

Beginner

Level

12

Comments

Crash Course 2: Invaders - Part 7

by Hectate (Updated on 2015-02-01)


Part 7: Adding Background Music to A Scene

Step 42: Now we need to add background music. Click the Events tab from within the Level One scene, which will bring up Stencyl Design Mode. We can use this to create game logic. In this case, we’re creating an Event directly rather than creating a fully modular Behavior.

Important Note: Generally, you want to create Behaviors because you can add them to any Actor Type or Scene that you want. Behaviors are made up of Events, so think of a Behavior as a portable Event container. We’re attaching Events directly here because we won’t be re-using anything we’re making here - the movement Event for our Ship won’t apply to the Enemy Ship Actors, for example.

Step 43: Click the + Add Event button in the Events pane on the left, move our mouse over the Basics option, and click on the When Creating Event.


The following "Created" event should appear as the first and only entry in our Events list.

Step 44: Now that we have the "when created" block in our workspace, we can add logic to our event. If you look all the way to the right, there is a "palette" of different logic blocks available to us, neatly organized into different categories. We are going to work with our music, so click the Sound & Images button in the Palette.

Next, left click and drag the Play Sound block in the Playback subcategory (shown above) over into the When Created block in the work area, and when the white bar appears, release the button. The block will snap into place.

Step 45: Left-click on the Sound dropdown button and a dialog will appear that lets you select which sound to play.

Step 46: Click the Choose Sound option and select the song we imported earlier.

Tip: Part 5 of this tutorial covers importing sounds. You can read about importing sounds again here.

The block will change to show the song it will play.

Step 47: Save your game (press Ctrl S or option S), then press the green Test Scene button. The music should be playing in the background.

 

 

We'll get to using the Explosion sound effect that we uploaded earlier when we handle destroying the Enemy ships. Now it’s time to move on to an Events that will let the player move the Ship using keyboard keys.

Click here to go to Part 8.

Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

12 Comments

jameswuisawesome
Wouldn't it make more sense if you loop the background music instead?
1 2 years, 4 weeks ago
MiguelMerrill
All good! :)
0 2 years, 2 months ago
t4om
At this point the ship doesn't load when I test the game.....what's wrong?
0 2 years, 5 months ago
Osman2001
Everything works fine for me!
0 2 years, 5 months ago
katriana89
no missile sound
0 2 years, 5 months ago
KrazieK
same problem...no explosion sound or missle fire sound
1 4 years, 4 months ago
Stotch
Someone commented in an earlier lesson that the png files do indeed work as sound files. All you have to do is click and drag the files from the assets folder into the add sound box. I tried it and it does work.
1 4 years, 6 months ago
swearingen
One issue is that in the "assets" folder the audio files are mis-labeled as .png files.
However, even changing the .png to .mp3 isn't the solution: the "space" audio file is so big that Stencyl won't import it without crashing.

I created a new loop, and (about 3MB) and it seemed to import ok.

0 4 years, 7 months ago
phyerboss
If I didnt know any better. I'd say the author of this tut is skipping over things. 1st off...How do we drop from the music editor to this point?! What event editor tab?! Im sorry. i am getting confused because the things being directed to in this tut. I am not seeing them. This especially includes the so-called "space track".
0 4 years, 8 months ago
massiveintellect
Sorry, disregard previous post. Was a display problem...
1 4 years, 11 months ago

Sign In to Comment