Step 15: Adding Lightsaber Swing Sound

Goal:


Now our lightsaber can turn on and off, but we want to add some sound effects to it while it’s on.

When you swing a lightsaber it makes noise, so we want to add some sound files to our app that activate when we swing our phone.

We are going to use a random picker so that our swing sounds are different and isn’t just the same sound played over and over again.

Steps:

  1. From AccelerometerSensor, place a Shaking block on the screen.
  2. From Control, place an IF/THEN block inside of the Shaking block.
  3. From Variables, attach a get block to the IF portion of the IF/THEN and set it to saberOn.
  4. From SaberSwing1, place a set SaberSwing1.Source to block inside of the THEN portion of the IF/THEN block.
  5. From List, attach a pick a random item list block to the SaberSwing1.Source block.
  6. From List, attach a make a list block to the end of the pick a random item list block.
  7. From Text, place an empty text box block in each of the make a list slots.
  8. Type “SaberSwing1.wav” into the first one.
  9. Type “SaberSwing2.wav” into the second one.
  10. From SaberSwing1, place a Play block.
  11. From SaberSwing1, place a Vibrate millisecs block.
  12. From Math, attach a 0(zero) block to the end of the Vibrate millisecs block.

Code: