Discuss Scratch

BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

So this is kind of a tough one. So I'm working on a project and I'm trying to work on the animations of the player. So the big issue I always stumble into is that every time I try any kind of animations on my projects they always overlap with other animations. So for example I'm working on a game and my character has different animations depending on their movement. So if they walk left then they will have an animation to walk left and if they walk right they they have an animation to walk right and so on. Everything ok so far but now whenever I try something like walking right and jumping instead of displaying the walking right animation and then the jump animation what it does is it overlaps both animations making it look pretty bad. So in my opinion I think the way I'm doing the animation on the project is what its making the animations to overlap, SO a little example I have of the way I make animations on my project is like this:
if <key [RightArrow v] pressed?> then
if <touching [Floor v] ?> then
if <[InAir?] = [No]> then
if <[Facing?] = [Right]> then

That's pretty much a small example of how I make animations. In case this is needed too this is how I make the player change sprites for their animations

forever
switch costume to [(Sprites) v]
end

repeat until <not <key [RightArrow v] pressed?>>
set [Sprites v] to [1]
wait (0.03) secs
set [Sprites v] to [2]
And so on
end

All sprites are are named by a number so that's how I just have to type the number so my player changes sprites. Anyway so this is pretty much how I make animations in my project but like I said most of the time when two animations happen instead of stopping the last animation and start the new animation it just plays both animations making them overlap. Is there any way I can make it so the animations don't overlap? I know this might be a little more tricky to answer but anyway hope y'all have a nice day! ^^

Last edited by BossRushFanatic (Sept. 16, 2024 21:10:07)

NMario84
Scratcher
1000+ posts

How do I implement animations in my project?

There's many different ways to doing your animations. I believe the most common is to use ‘next costume’ block with a ‘wait () seconds’ block. I typically use lists to organize my animation frames and display times. It's a little more complicated though.

https://en.scratch-wiki.info/wiki/Animating_a_Sprite
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

NMario84 wrote:

There's many different ways to doing your animations. I believe the most common is to use ‘next costume’ block with a ‘wait () seconds’ block. I typically use lists to organize my animation frames and display times. It's a little more complicated though.

https://en.scratch-wiki.info/wiki/Animating_a_Sprite
I already know how to make animations. What I'm looking for is how do I make it so they don't overlap with other animations. I want it so the past animation that was playing gets replaced by the new animation instead of playing them both at the same time
J41n
Scratcher
100+ posts

How do I implement animations in my project?

BossRushFanatic wrote:

NMario84 wrote:

There's many different ways to doing your animations. I believe the most common is to use ‘next costume’ block with a ‘wait () seconds’ block. I typically use lists to organize my animation frames and display times. It's a little more complicated though.

https://en.scratch-wiki.info/wiki/Animating_a_Sprite
I already know how to make animations. What I'm looking for is how do I make it so they don't overlap with other animations. I want it so the past animation that was playing gets replaced by the new animation instead of playing them both at the same time
Oh i can help with this
Can you give me a example project or a project link because its just going to be a big block of code here on the forums
I personally think its a hassle doing code here
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

J41n wrote:

BossRushFanatic wrote:

NMario84 wrote:

There's many different ways to doing your animations. I believe the most common is to use ‘next costume’ block with a ‘wait () seconds’ block. I typically use lists to organize my animation frames and display times. It's a little more complicated though.

https://en.scratch-wiki.info/wiki/Animating_a_Sprite
I already know how to make animations. What I'm looking for is how do I make it so they don't overlap with other animations. I want it so the past animation that was playing gets replaced by the new animation instead of playing them both at the same time
Oh i can help with this
Can you give me a example project or a project link because its just going to be a big block of code here on the forums
I personally think its a hassle doing code here
I'm trying to keep the project private for now so I don't know how I could send you the link tho
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

J41n wrote:

BossRushFanatic wrote:

NMario84 wrote:

There's many different ways to doing your animations. I believe the most common is to use ‘next costume’ block with a ‘wait () seconds’ block. I typically use lists to organize my animation frames and display times. It's a little more complicated though.

https://en.scratch-wiki.info/wiki/Animating_a_Sprite
I already know how to make animations. What I'm looking for is how do I make it so they don't overlap with other animations. I want it so the past animation that was playing gets replaced by the new animation instead of playing them both at the same time
Oh i can help with this
Can you give me a example project or a project link because its just going to be a big block of code here on the forums
I personally think its a hassle doing code here
You know what here's the link. I just really hope not many people see it. Please let me know what you come up with so I can make the project private again thank you!! ^^ https://scratch.mit.edu/projects/1051102674
GamesReinvented
New Scratcher
100+ posts

How do I implement animations in my project?

The reason the animations overlap is because you're using wait blocks inside the scripts. Since you have wait blocks, past animations keep running and thus overlap eachother. One way to counteract this is to use a frame variable, and use a script similar to this:
define animate from costume (c1) to costume (c2) at (fps) fps
switch costume to ((c1) + (([floor v] of (frame)) mod (((c2) - (c1)) + (1)))) //if c2 is smaller than c1 then it breaks, so order your frames
change [frame v] by ((fps) / (30))
Where c1 is the starting costume, and c2 is the ending costume. Currently, your animations are at around 25 FPS, so you can use that for reference or adjust the number. When starting a new animation, make sure to set frame to 0, or you'll start part-way in the animation.

I would remix/edit your project with this implemented, but I don't have the time currently and could do so later.

Last edited by GamesReinvented (Sept. 16, 2024 23:29:02)

BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

GamesReinvented wrote:

The reason the animations overlap is because you're using wait blocks inside the scripts. Since you have wait blocks, past animations keep running and thus overlap eachother. One way to counteract this is to use a frame variable, and use a script similar to this:
define animate from costume (c1) to costume (c2) at (fps) fps
switch costume to ((c1) + (([floor v] of (frame)) mod (((c2) - (c1)) + (1)))) //if c2 is smaller than c1 then it breaks, so order your frames
change [frame v] by ((fps) / (30))
Where c1 is the starting costume, and c2 is the ending costume. Currently, your animations are at around 25 FPS, so you can use that for reference or adjust the number. When starting a new animation, make sure to set frame to 0, or you'll start part-way in the animation.

I would remix/edit your project with this implemented, but I don't have the time currently and could do so later.
Got it! I will try to test this out. Thank you!! ^^
WarriorYeet100V2
Scratcher
13 posts

How do I implement animations in my project?

To implement animations on sprites, you're going to need more than one costume. (I'm sure you know this) But you can try something like this for the code:
when green flag clicked
forever
if <<key [Right Arrow] pressed?>> then
if <<[Facing] = [Right]>> then
next costume
wait (0.03) secs
I hope this helps you! Best of luck!

Last edited by WarriorYeet100V2 (Sept. 17, 2024 16:16:52)

Sedef-Eercc
Scratcher
100+ posts

How do I implement animations in my project?

BossRushFanatic wrote:

So this is kind of a tough one. So I'm working on a project and I'm trying to work on the animations of the player. So the big issue I always stumble into is that every time I try any kind of animations on my projects they always overlap with other animations. So for example I'm working on a game and my character has different animations depending on their movement. So if they walk left then they will have an animation to walk left and if they walk right they they have an animation to walk right and so on. Everything ok so far but now whenever I try something like walking right and jumping instead of displaying the walking right animation and then the jump animation what it does is it overlaps both animations making it look pretty bad. So in my opinion I think the way I'm doing the animation on the project is what its making the animations to overlap, SO a little example I have of the way I make animations on my project is like this:
if <key [RightArrow v] pressed?> then
if <touching [Floor v] ?> then
if <[InAir?] = [No]> then
if <[Facing?] = [Right]> then

That's pretty much a small example of how I make animations. In case this is needed too this is how I make the player change sprites for their animations

forever
switch costume to [(Sprites) v]
end

repeat until <not <key [RightArrow v] pressed?>>
set [Sprites v] to [1]
wait (0.03) secs
set [Sprites v] to [2]
And so on
end

All sprites are are named by a number so that's how I just have to type the number so my player changes sprites. Anyway so this is pretty much how I make animations in my project but like I said most of the time when two animations happen instead of stopping the last animation and start the new animation it just plays both animations making them overlap. Is there any way I can make it so the animations don't overlap? I know this might be a little more tricky to answer but anyway hope y'all have a nice day! ^^

I think the forever block may be a mistake bc its trying to run one animation forever while the other ones happening and it gets confused and glitches
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

Sedef-Eercc wrote:

BossRushFanatic wrote:

So this is kind of a tough one. So I'm working on a project and I'm trying to work on the animations of the player. So the big issue I always stumble into is that every time I try any kind of animations on my projects they always overlap with other animations. So for example I'm working on a game and my character has different animations depending on their movement. So if they walk left then they will have an animation to walk left and if they walk right they they have an animation to walk right and so on. Everything ok so far but now whenever I try something like walking right and jumping instead of displaying the walking right animation and then the jump animation what it does is it overlaps both animations making it look pretty bad. So in my opinion I think the way I'm doing the animation on the project is what its making the animations to overlap, SO a little example I have of the way I make animations on my project is like this:
if <key [RightArrow v] pressed?> then
if <touching [Floor v] ?> then
if <[InAir?] = [No]> then
if <[Facing?] = [Right]> then

That's pretty much a small example of how I make animations. In case this is needed too this is how I make the player change sprites for their animations

forever
switch costume to [(Sprites) v]
end

repeat until <not <key [RightArrow v] pressed?>>
set [Sprites v] to [1]
wait (0.03) secs
set [Sprites v] to [2]
And so on
end

All sprites are are named by a number so that's how I just have to type the number so my player changes sprites. Anyway so this is pretty much how I make animations in my project but like I said most of the time when two animations happen instead of stopping the last animation and start the new animation it just plays both animations making them overlap. Is there any way I can make it so the animations don't overlap? I know this might be a little more tricky to answer but anyway hope y'all have a nice day! ^^

I think the forever block may be a mistake bc its trying to run one animation forever while the other ones happening and it gets confused and glitches
How could I fix that? Cuz without the forever block I cannot make the animation start whenever I want it will only start when I begin the project. The forever block helps me be able to use the animation whenever I want but yea I also think that's why it also glitches by also playing other animations
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

GamesReinvented wrote:

The reason the animations overlap is because you're using wait blocks inside the scripts. Since you have wait blocks, past animations keep running and thus overlap eachother. One way to counteract this is to use a frame variable, and use a script similar to this:
define animate from costume (c1) to costume (c2) at (fps) fps
switch costume to ((c1) + (([floor v] of (frame)) mod (((c2) - (c1)) + (1)))) //if c2 is smaller than c1 then it breaks, so order your frames
change [frame v] by ((fps) / (30))
Where c1 is the starting costume, and c2 is the ending costume. Currently, your animations are at around 25 FPS, so you can use that for reference or adjust the number. When starting a new animation, make sure to set frame to 0, or you'll start part-way in the animation.

I would remix/edit your project with this implemented, but I don't have the time currently and could do so later.
It worked! (Kind of) Ok so I tried what you told me and it works! Not only is it easier to make the animations in the project but it saves A LOT of time by not having to add variable blocks and waiting blocks. Two problems tho, first problem is that the animations only work if I keep pressing the key that activates them. I mean that sounds good for walking animations cuz when walking you will keep pressing the key so that's good cuz it repeats the animation but for animations like the jumping animation doesn't work that well cuz I have to keep pressing the jump key instead of just pressing it once. I will see if I can fix that but in case you know how to fix it please let me know. Also second problem, it seems it breaks my x and y position blocks for some reason. they also use custom blocks for them to work and for some reason by adding this new custom block it just messes up the x and y custom blocks I made making the player not being able to move (Although it can jump so I dunno what's happening in there lol) Other than those 2 problems this works great! I will try to find a way to fix these problems. anyway thank you so much and have a good one!! ^^

EDIT: ok I found out the reason of the second problem. It seems by binding the key for the animation with the same key to walk messes up the movement. I haven't fixed it but now I know what causes it so I think I can find out why it messes up movement now. For now I just gotta find a way to fix the first problem now.

Last edited by BossRushFanatic (Sept. 17, 2024 20:22:00)

GamesReinvented
New Scratcher
100+ posts

How do I implement animations in my project?

BossRushFanatic wrote:

EDIT: ok I found out the reason of the second problem. It seems by binding the key for the animation with the same key to walk messes up the movement. I haven't fixed it but now I know what causes it so I think I can find out why it messes up movement now. For now I just gotta find a way to fix the first problem now.
You can fix the jumping by changing to have a repeat until the jump animation is done, or some other animation cancels it out, like the force fall.
when green flag clicked
forever
if <key (jump key v) pressed> then
other if checks {
repeat until <<(costume (number v) ::looks) = (y)> or <some other animation starts ::variables>>
animate from costume (x) to costume (y) at (fps) fps ::custom
} ::grey
end
end
You could set a variable to detect whenever a animation starts to stop said animation mid through.
BossRushFanatic
New Scratcher
54 posts

How do I implement animations in my project?

GamesReinvented wrote:

BossRushFanatic wrote:

EDIT: ok I found out the reason of the second problem. It seems by binding the key for the animation with the same key to walk messes up the movement. I haven't fixed it but now I know what causes it so I think I can find out why it messes up movement now. For now I just gotta find a way to fix the first problem now.
You can fix the jumping by changing to have a repeat until the jump animation is done, or some other animation cancels it out, like the force fall.
when green flag clicked
forever
if <key (jump key v) pressed> then
other if checks {
repeat until <<(costume (number v) ::looks) = (y)> or <some other animation starts ::variables>>
animate from costume (x) to costume (y) at (fps) fps ::custom
} ::grey
end
end
You could set a variable to detect whenever a animation starts to stop said animation mid through.
Sorry to bother but this is for problem 1 or problem 2?
GamesReinvented
New Scratcher
100+ posts

How do I implement animations in my project?

BossRushFanatic wrote:

Sorry to bother but this is for problem 1 or problem 2?
This is for problem 1.
FiredGod
Scratcher
6 posts

How do I implement animations in my project?

GamesReinvented wrote:

The reason the animations overlap is because you're using wait blocks inside the scripts. Since you have wait blocks, past animations keep running and thus overlap eachother. One way to counteract this is to use a frame variable, and use a script similar to this:
define animate from costume (c1) to costume (c2) at (fps) fps
switch costume to ((c1) + (([floor v] of (frame)) mod (((c2) - (c1)) + (1)))) //if c2 is smaller than c1 then it breaks, so order your frames
change [frame v] by ((fps) / (30))
Where c1 is the starting costume, and c2 is the ending costume. Currently, your animations are at around 25 FPS, so you can use that for reference or adjust the number. When starting a new animation, make sure to set frame to 0, or you'll start part-way in the animation.

I would remix/edit your project with this implemented, but I don't have the time currently and could do so later.
Thank you so much. Now I can animate very cleanly.

Powered by DjangoBB