rockpirate
rockpirate

Reputation: 1

Controlling different types of sprite animation in Scratch

I'm building a platformer in Scratch 3.0 where a player can run, jump, crouch, and has a few basic attacks. Right now I have animation set up under a custom block like this example for the idle:

switch to costume (1+((floor of (timer*10)) mod 6)

This loops the costume around with the game timer as long as the animation conditions are met; and works fine for idle, run, and jump—however I'm not sure how to implement something like a crouch (three costumes/frames), which always needs to start on a specific costume, play through two additional costumes, then stop until the down key is released. Similarly, I need attack animations to always start on a specific costume, and play the entire animation through sequentially.

I hope that makes sense. Any advice for a good way to implement this, or additional parameters I need to include to make that work?

Upvotes: 0

Views: 569

Answers (2)

EldarT
EldarT

Reputation: 31

So let's say that you want to start walking. you can set the costume to the first frame of that, and then go to the next costume a few times (maybe also add in a wait block depending on the fps of your animation) and then if the costume goes past your animation frames, just set the costume back. Here is an image, but you can just ignore the custom block, and pretend that the if else is in the forever. i just like using custom blocks because of the run without screen refresh. (The mage of the code needed) sorry if this is confusing, i'm just bad at writing

Upvotes: 1

GD Vicious bee
GD Vicious bee

Reputation: 47

How about using a state variable that is a number?
Example, lets create a block called crouch and apply a counter so that if the down arrow key is pressed, you set counter to 1 and then to 2 for the crouching sprites. Then you use a wait until <=> block to wait until crouching is gone.
Now you do the same for the others

Upvotes: 0

Related Questions