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

#1 2011-01-22 07:24:18

the_storm_of_stone
Scratcher
Registered: 2011-01-22
Posts: 24

Animating a sprite while still

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

 

#2 2011-01-22 11:06:40

Lar-Rew
Scratcher
Registered: 2010-02-19
Posts: 100+

Re: Animating a sprite while still

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

 

#3 2011-01-22 12:11:17

the_storm_of_stone
Scratcher
Registered: 2011-01-22
Posts: 24

Re: Animating a sprite while still

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

 

#4 2011-01-22 12:36:27

ian528
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: Animating a sprite while still

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!  smile

Last edited by ian528 (2011-01-22 12:39:04)

Offline

 

#5 2011-01-22 14:18:43

the_storm_of_stone
Scratcher
Registered: 2011-01-22
Posts: 24

Re: Animating a sprite while still

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  smile

Offline

 

#6 2011-01-22 14:27:26

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Animating a sprite while still

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


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

#7 2011-01-22 14:39:18

ian528
Scratcher
Registered: 2010-05-25
Posts: 500+

Re: Animating a sprite while still

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

 

#8 2011-01-22 15:47:44

the_storm_of_stone
Scratcher
Registered: 2011-01-22
Posts: 24

Re: Animating a sprite while still

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

Offline

 

Board footer