Search code examples
mit-scratch

Why does the sprite costume not change?


I'm just starting to play about in Scratch...

I seem to have a sprite of a cat with two 'costumes', which I guess are like frames.

I made this sequence:

enter image description here

...but when I click the green flag the cat moves to the right but the costumes don't switch.

If I make a simpler sequence:

enter image description here

...and manually change the costume in the drop-down then the costume does change.

What is the limitation here?


Solution

  • This is by design. By default, loops have a built-in delay of about 1/30 second. (There are ways to eliminate that delay, but that is off-topic here.) This was done to help inexperienced programmers witness the effect of a loop; possibly also to make execution speed more consistent (regardless of client's CPU power).

    In your case, that means costume2 will be visible for 1/30 second before switching back to costume1. Costume1 on the other hand, is instantly followed up by costume2. Consequently, you will only see costume2.

    There are various ways to fix that.

    1. Change your script to repeat 5 { move 10 steps; next costume; } This gives both costumes an implicit 1/30 second delay. If this is still too short, add a delay (wait ... seconds). Note: next costume wraps around, so assuming the sprite has 2 costumes, it will flip back and forth between costume1 and costume2.
    2. Too jerky? Use glide ... secs to ... instead of 'move and wait'.
    3. Or just take smaller steps; swap costume once every few steps.
    4. Make two separate scripts running in parallel, one for the movement, the other for switching costumes. That makes it easier to specify a different delay for each.