Hi, I just signed up on the site in the hopes that one of you more experienced Scratchers would be able to tell me how to animate a sprite between two or three costumes in a "breathing" cycle. As in when the sprite is not moving but it switches costumes in a loop to appear like it's waiting or breathing until it is moved again.
Any help?
Offline
You can define multiple costumes for a sprite ("costumes" tab), and then you can tell it to switch costumes with these blocks:
<next costume>
<switch to costume[
Note that with the second block, you can refer to a costume by name OR by number.
Offline
Yes, but how would I get it to recognise that when no key is being pressed, it should cycle through those costumes, and stop and switch to another set of costumes when a key is pressed?
Offline
Use:
if<not <<right> and <left> and <down> and <up> pressed>>,
forever
Switch to (next desired costume)
Wait (desired time)
Switch to next costume..... ( keep going until you are done with the required set of cos.)
------------------------------------------
else
switch to (other desired costume)
Hope I helped!
Last edited by ian528 (2011-01-22 12:39:04)
Offline
No, sorry I couldn't get that to work.... The sprite didn't go through the cycle when still, but switched to the costume I wanted costume whenever I jumped. Also, it sometimes went through the floor. I use a separate costume for jumping, and I'm trying to put in a walk cycle too... If no-one can help me with the breathing cycle, then what's the best way to program a walking cycle?
Thanks anyway
Offline
Best way to do this in scratch can be seen in this project http://scratch.mit.edu/projects/archmage/291819
Download it and use the scripts
Offline
archmage wrote:
Best way to do this in scratch can be seen in this project http://scratch.mit.edu/projects/archmage/291819
Download it and use the scripts
This: http://scratch.mit.edu/projects/archmage/291819
Last edited by ian528 (2011-01-22 14:39:32)
Offline
I can't understand that... I just started using the program and this is the script I've been using to move and jump:
When (green flag) is clicked
Switch to costume (sprite1)
Point in direction 90
Go to x: -141 y: -87
Set (Maxspeed) to 14
{
--Forever
[--If <<Key (left arrow) pressed? >and<(abs) of (xVelocity) < (Maxspeed)>>
----Change (xVelocity) by (-0.7)]
[--If <<Key (right arrow) pressed? >and<(abs) of (xVelocity) < (Maxspeed)>>
----Change (xVelocity) by (0.7)]
[--If <(xVelocity) > 0>
----point in direction 90
--Else
----point in direction -90]
Change x by (xVelocity)
Set (xVelocity) to <(xVelocity)* 0.87>
}
That was for moving. This is what I use for jumping while switching costumes:
When (green flag) is clicked
{
--Forever
[--If <touching (Ground)?>
----Switch to costume (sprite 1)
----Set (yVelocity) to 1
[--If <key (up arrow) pressed?>
----Switch to costume (jump)
----Set (yVelocity) to 15]]
Change (yVelocity) by -1
Change y by (yVelocity)
}
I don't know where to put these costume switches...
Offline