In this add-on you willadd another background track for theDJ sprite to mix and key pressevent so the user can switch the track.
To add another track, select the DJ sprite,click on the sounds tab, and selectthe sound from the sound library.
This example will use the sound Techno2for the second background track.
Next, go to the code tab, add to andtweak your code so that the usercan play one background song at a time.
To do that, go to the variable menu, click mega variable,and crate a new variable called: song.
Next, add code that will allowthe user to toggle back and forth between songsby pressing either the one or two key.
To make that happen, go to the variable menu,select a set songtube block and change the value to one.
From the events menu, drag out awhen space key press block andconnect it to the soundtube one block.
From the dropdown menu select the one key.
This block set now reads, whenone key pressed, set song to one.
Perfect, now duplicate this block stackfor the two key, and set the song to two.
To adjust the code that plays thebackground song, remove the play sounduntil done block from the forever loop.
In this example the background song is techno.
Techno should play if the valueof the variable song is equal to one.
Drag out an if then conditional blockfrom the control menu and insert it into the forever loop.
Then, go to the operators menu,drag out a green equal operator block,and insert it into the diamond shapedconditional slot of the if then block.
From the variable menu, drag outthe variable song and place it into thegreen operator block on the left side of the equal sign.
On the right side of the equalsign, change the value to one.
Place the play sound until done blockyou initially removed inside the if then statement.
The conditional statement now reads:If song equals one, then play sound until done.
In this example the sound is techno,but George will show the soundthat you chose for your project.
To copy these blocks, right click on theif then conditional block and select duplicate.
Place the copy beneath the firstif then conditional in your block stack,making sure it is still inside the forever loop.
Change the values on the green operatorblock so it reads: song equal two.
Click the drop down menu of theplay sound block and select the new sound.
In this example, techno2.
Texture code: click the green flagand press the one key, then the two key.
The song should switch after it finishes playing.
When you press the one or two key,you should also see the value in thesong variable change to either one or two.
Now it's your turn: Add a second background songto your project from the sound library.
Create a new variable called: song.
Create the codes to set song equalto one when the one key is pressed.
Create the code to set the song equalto two when the two key is pressed.
And lastly, create if then conditionalsto play the first track if song equals one,and to play the second track if song equals two,and insert them inside the forever loopfor the background sound block stack.
Choose an Add-On
Make your DJ dance and twist.
Add a dancer sprite that has multiple costumes, and give it some moves.
Add a light show to your DJ's performance.
Program an audience for your DJ.
Switch the Background Track
Switch the background track from within your project.