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.
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.