As of late 2021, we are in the process of updating Stencylpedia and fixing up outdated & broken content. Thanks for your patience!







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!


Dang this is mainly Fun/boring/stupide...... but I still like it a lot.
0 5 months, 3 weeks ago
Hello, I'm not getting any background music when I test the scene.
0 1 year, 9 months ago
I figured out the problem, but I'm not sure how to solve it... The kit used in this crash course has the images scaled much smaller than they are supposed to be. The ships and the aliens, along with the background, are minuscule. So, the play area is massive comparatively. Update the crash course kit for us, please!
0 2 years, 4 months ago
@nikoscot Go to the "Level One" tab, and on the left side menu which displays the list of events in that scene, you will see the button "Add Scene" there. It's adjacent to a "Remove Scene," "Move Scene Up," and "Move Scene Down" buttons.
0 2 years, 7 months ago
I can't find the "Add Event" button.
Up on the bar where the "Edit" button is, it has the "Add Event" button but when I press it it doesn't do anything...
Any suggestions?

0 3 years, 5 months ago
Wouldn't it make more sense if you loop the background music instead?
2 6 years, 6 months ago
All good! :)
0 6 years, 7 months ago
At this point the ship doesn't load when I test the game.....what's wrong?
0 6 years, 10 months ago
Everything works fine for me!
0 6 years, 10 months ago
no missile sound
0 6 years, 10 months ago

Sign In to Comment