Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Animations in a playable sprite..?
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
Okay, so I've been workin' on this game for months and I cannot seem to figure out how to make the character have a movement animation while still being playable. For example (this is an example only), you get onto a game. There is a stickman moving his head side-to-side at a slow pace. When you try to use the arrow keys and move that stickman, the side-to-side animation screws with the walking animation because it's trying to switch to the walking animation. Is there any way to have it so the stickman can move at a steady pace with smooth animations; still being able to have the walking animation and side-to-side one?
-Thanks, really appreciate it!
-Thanks, really appreciate it!

- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
Here's a clear walk through (if you're too lazy to read it all). I need a bit of advice on my character's animations. Are there any good ways on having the character animations not interfere with each other? This is a video game, not an animation. 

- Despicable_Dad
-
Scratcher
500+ posts
Animations in a playable sprite..?
I can only think of two solutions:
1. Double (or more) up on your sprite's costumes. (E.g., one for walk1 with head left, one for walk1 with head right, one for walk2 with head left, one for walk 2 with head right), or
2. Have separate sprites for head and body, and move them about as a pair.
1. Double (or more) up on your sprite's costumes. (E.g., one for walk1 with head left, one for walk1 with head right, one for walk2 with head left, one for walk 2 with head right), or
2. Have separate sprites for head and body, and move them about as a pair.
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
Alrighty, I'll take the advice! We'll see how it turns out.
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
I'd love any other advice too! o_O
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
No. But, I actually know what the problem is. The ‘repeat until’ block is screwing with meh walking animations! There's not enough time for the ‘repeat until’ block to stop. Any advice for that? Is there a way I can have the animations stop immediately instead of just waiting until they're done repeating?
- Despicable_Dad
-
Scratcher
500+ posts
Animations in a playable sprite..?
This is why it would be helpful if your project was shared. Without knowing how you've done things, it's difficult to suggest changes. From what you say, about waiting for them to stop, you are doing your animations differently from how I would have done them… but what you have done remains a mystery unless you give a fairly detailed description of how your scripts work, or show us here using scratchblocks, or… share. The last one is easiest for you, but also easier for people who might be able to help. The easier you make it for people to help, the more help you're likely to get. (And the less wrong the help will be, lol.)
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
repeat until <>
switch costume to [Animation 1 v]
wait (.1) secs
switch costume to [Animation 2 v]
wait (.1) secs
switch costume to [Animation 3 v]
wait (.1) secs
end
It goes a little something like this.
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
That's a problem because it'll still have a couple milliseconds of that movement (up and down) when one of the arrow keys are pressed. That movement will interfere with my walking animations (when an arrow key is pressed).
- Despicable_Dad
-
Scratcher
500+ posts
Animations in a playable sprite..?
I have a couple of suggestions that might help, but can't guarantee they won't interfere with other things, as I don't know what else is going on in other scripts. (E.g., repeat until what?)
It'll take me ages showing it with Scratchblocks (and I'll probably mess it up) but give me a few minutes and I'll make a mini project to explain.
It'll take me ages showing it with Scratchblocks (and I'll probably mess it up) but give me a few minutes and I'll make a mini project to explain.
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
repeat until <key [up arrow or down arrow or left arrow or right arrow v] pressed?>
end

- TheLogFather
-
Scratcher
1000+ posts
Animations in a playable sprite..?
Are the animations *meant* to run together at the same time? If so, then I don't see how you can expect it to work without either creating all the appropriate costumes, or else splitting the parts of the sprite up into separate sprites that have costumes for things they need to do independently of each other.
But if you have separate scripts for your animations, and the animations don't need to happen at the same time as each other, then how about using “stop other scripts in sprite”?
But if you have other running scripts in the sprite that you don't want to stop, then another possibility is to have a single script started from a broadcast, and having all animations done within that script, with a variable which says which animation to do.
You can split it with custom blocks to make it more manageable, like this, for example:
When you want to start a new animation loop, just set the variable and send the broadcast – it will automatically and immediately *stop* the current animation, and start the new one.
But if you have separate scripts for your animations, and the animations don't need to happen at the same time as each other, then how about using “stop other scripts in sprite”?
But if you have other running scripts in the sprite that you don't want to stop, then another possibility is to have a single script started from a broadcast, and having all animations done within that script, with a variable which says which animation to do.
You can split it with custom blocks to make it more manageable, like this, for example:
when I receive [restart animation v]And as an example (YES! -you *can* use ‘forever’ in here, 'cos sending the broadcast again will terminate it!):
if <(animation)=[walk]> then
do walk animation loop :: custom block
else
if <(animation)=[jump]> then
do jump animation loop :: custom block
else
do idle animation loop :: custom block
end
end
define do walk animation loop
forever
do all the costume changing and waiting... :: grey
end
When you want to start a new animation loop, just set the variable and send the broadcast – it will automatically and immediately *stop* the current animation, and start the new one.

Last edited by TheLogFather (Feb. 22, 2017 01:08:39)
- Despicable_Dad
-
Scratcher
500+ posts
Animations in a playable sprite..?
lol, I have been ninja'd by TheLogFather, who's far more knowledgeable than me. (Not to mention quicker at doing scratchblocks than I am at just dragging real ones!)
Still, this demo might be helpful to you. https://scratch.mit.edu/projects/146488776/
Still, this demo might be helpful to you. https://scratch.mit.edu/projects/146488776/
- jojohallbrook
-
Scratcher
100+ posts
Animations in a playable sprite..?
I'll use both of your techniques! Thanks guys! It may take a good gettin' used to.. But, I think I'll be able to handle it. 

say [Thanks, glad you stuck long enough to help!]
- mstone326
-
Scratcher
1000+ posts
Animations in a playable sprite..?
See if this helps as an option. TheLogFather's method is the best way to go in my opinion. I am currently having an issue with a multi jump costume range and I think that his method will help with that. Wanted to throw another option out there as well.
Look inside the project at the Duck's custom animate block. Since using “next costume” would change 30 frames per second I have to slow down that animation otherwise he walks too fast. So I change his frame by a decimal to slow it down. Then I stay within the range of his animation cycles.
Here are his cycles (this is also on the custom block as a comment and the other scripts are commented as well). Hope this helps.
Action costume range
idle 1-7
running 8-15
jumping 16
shoot 17
falling 18
pound 19
hitbox 20
https://scratch.mit.edu/projects/108361157/#editor
Look inside the project at the Duck's custom animate block. Since using “next costume” would change 30 frames per second I have to slow down that animation otherwise he walks too fast. So I change his frame by a decimal to slow it down. Then I stay within the range of his animation cycles.
Here are his cycles (this is also on the custom block as a comment and the other scripts are commented as well). Hope this helps.
Action costume range
idle 1-7
running 8-15
jumping 16
shoot 17
falling 18
pound 19
hitbox 20
https://scratch.mit.edu/projects/108361157/#editor
Last edited by mstone326 (Feb. 22, 2017 13:35:15)
- TheLogFather
-
Scratcher
1000+ posts
Animations in a playable sprite..?
Look inside the project at the Duck's custom animate block. Since using “next costume” would change 30 frames per second I have to slow down that animation otherwise he walks too fast. So I change his frame by a decimal to slow it down. Then I stay within the range of his animation cycles.Yes, that's another way to get the animation at the rate you want when you're also using a technique that I would recommend for games – having only one single main control loop in one sprite (which sends a broadcast at every frame that all other sprites/clones respond to and do work for only one frame), rather than having loops running all over the project in all of the various other sprites. (Having a single main loop also helps you synchronise your sprites/clones a lot more easily.)
An example would be my recent BatCave3D demo game. It has a single loop in the “Control” sprite, and the flapping animation for the bat's wings is done using a variable which changes a little each frame (in response to the “tick” broadcast sent by the main loop). The variable is then rounded to get the desired costume number for the wings. (Note how it checks if the desired costume number is different from the one it's currently on before switching – otherwise Scratch will end up doing a costume ‘non-switch’ a lot of the time, ‘cos the costume doesn’t yet need to move on from where it currently is).
Another useful benefit of doing this is that it means you can really easily change the apparent speed of your game just by making the costume variable increase at a slightly higher rate. (Again, see my BatCave3D demo, since that slowly gets faster and faster as the game progresses.)
Last edited by TheLogFather (Feb. 22, 2017 14:56:28)
- CCCP-Productions
-
New Scratcher
1 post
Animations in a playable sprite..?
I have a question about sprite animation. In a project I'm working on I have a playable sprite that moves along both axis' and I need animations for all 4 directions. I have scripts for the animations but when you run the project, only the animations for travelling on the x-axis work. I've looked through the code many times and can't find any errors.
- Tallented-Code-bot
-
Scratcher
100+ posts
Animations in a playable sprite..?
I have a question about sprite animation. In a project I'm working on I have a playable sprite that moves along both axis' and I need animations for all 4 directions. I have scripts for the animations but when you run the project, only the animations for traveling on the x-axis work. I've looked through the code many times and can't find any errors.(1) you should share the project so we can see the actual scripts
(2) you should make a new forum thread instead of using an old one ( you do this by going to the top of whichever forum you want the thread in
and click the “new topic” button).
- Discussion Forums
- » Help with Scripts
-
» Animations in a playable sprite..?




