This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-26 07:02:15

Teamwild
New Scratcher
Registered: 2012-08-26
Posts: 1

How to animate a sprite while a sound is playing

Hi,
I'm trying to animate a sprite while a sound is playing. I don't really want to have the loop hard coded because that would require a code change if the sound changes.

Below is the script so far but I know the reset of the PlayingMusic variable isn't right.

when
space
key pressed
set
PlayingMusic
to
1
play sound
GuitarChords1
forever if
PlayingMusic
=
1
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-c
wait
0.1
secs
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-a
set
PlayingMusic
to
0

Thanks.

Offline

 

#2 2012-08-26 07:06:11

BirdByte
Scratcher
Registered: 2012-07-07
Posts: 1000+

Re: How to animate a sprite while a sound is playing

Just do this:

when
space
key pressed
play sound
GuitarChords1
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-c
wait
0.1
secs
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-a

smile


http://i50.tinypic.com/312u714.jpg

Offline

 

#3 2012-08-26 10:27:10

TheScratchChatter
Scratcher
Registered: 2012-08-18
Posts: 93

Re: How to animate a sprite while a sound is playing

Teamwild wrote:

Hi,
I'm trying to animate a sprite while a sound is playing. I don't really want to have the loop hard coded because that would require a code change if the sound changes.

Below is the script so far but I know the reset of the PlayingMusic variable isn't right.

when
space
key pressed
set
PlayingMusic
to
1
play sound
GuitarChords1
forever if
PlayingMusic
=
1
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-c
wait
0.1
secs
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-a
set
PlayingMusic
to
0

Thanks.

The problem is that the forever if block checks the condition (if playingmusic=1) once, and then if true, will repeat forever. Try:

Forever
if
playingmusic=1
do rest of code


http://i46.tinypic.com/2lxea91.png

Offline

 

#4 2012-08-26 10:29:57

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: How to animate a sprite while a sound is playing

TheScratchChatter wrote:

Teamwild wrote:

Hi,
I'm trying to animate a sprite while a sound is playing. I don't really want to have the loop hard coded because that would require a code change if the sound changes.

Below is the script so far but I know the reset of the PlayingMusic variable isn't right.

when
space
key pressed
set
PlayingMusic
to
1
play sound
GuitarChords1
forever if
PlayingMusic
=
1
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-c
wait
0.1
secs
switch to costume
ballerina-b
wait
0.1
secs
switch to costume
ballerina-a
set
PlayingMusic
to
0

Thanks.

The problem is that the forever if block checks the condition (if playingmusic=1) once, and then if true, will repeat forever. Try:

Forever
if
playingmusic=1
do rest of code

A common misconception, it actually does the exact same thing.
If the sound is the same length as the animation, then you can just use BirdByte's script


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#5 2012-08-26 10:35:52

henley
Scratcher
Registered: 2008-06-21
Posts: 1000+

Re: How to animate a sprite while a sound is playing

zammer990 wrote:

A common misconception, it actually does the exact same thing.
If the sound is the same length as the animation, then you can just use BirdByte's script

^^^ This.

If the sound is not the same length, and you want it to be, then time the changing of the costumes differently.


"I've worked so hard for you and you give me nothing in return. Do you need help... Or do I?"

Offline

 

#6 2012-08-26 10:40:02

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: How to animate a sprite while a sound is playing

henley wrote:

zammer990 wrote:

A common misconception, it actually does the exact same thing.
If the sound is the same length as the animation, then you can just use BirdByte's script

^^^ This.

If the sound is not the same length, and you want it to be, then time the changing of the costumes differently.

Or, you could do this

when clicked
or whatever starts the animation
forever
if
play sounds
=
1
play sound
music
when clicked
set
play music
to
1
animation
set
play music
to
0
stop all pinks
sounds

Last edited by zammer990 (2012-08-26 10:40:36)


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

Board footer