How To Make An 8-Directional Movement System With Animations! | Scratch Tutorials

DkUniverse
31 Jul 202216:38

Summary

TLDRIn this Scratch tutorial, the creator demonstrates how to implement basic 2D eight-directional movement with animations for game development. The tutorial builds upon a previous video, adding new elements and a more refined approach. Starting with setting up sprite movements using arrow keys or WASD, the creator explains using X and Y axes for motion and adjusting speed. The video also covers how to add animations when moving and idle poses when stationary. It's designed for beginners, but introduces more complex concepts like frame switching and costume animations.

Takeaways

  • 😀 Basic 2D eight-directional movement with animations is being taught in this Scratch tutorial.
  • 😎 The tutorial focuses on both arrow key and WASD movement control for a sprite.
  • 🖼️ You only need one direction sprite, which will automatically adjust using the 90-degree plane in Scratch.
  • 🔄 To make the sprite move, changes in the x and y coordinates are used rather than the built-in motion blocks.
  • 🐾 The speed of movement can be controlled by adjusting the x and y coordinate changes.
  • 🧑‍💻 Animations are added by switching between costumes based on movement directions.
  • ↔️ Sprite rotation is set to left and right to ensure correct movement animation without circular motion.
  • 🎥 A custom 'get frame' block is created to control the animation frame switching for smoother transitions.
  • 🎮 An idle pose or costume is used when no movement is detected, adding realism to the animation.
  • 🕹️ Complex key-sensing logic is implemented to handle multiple key presses and ensure smooth animation transitions.

Q & A

  • What is the purpose of the tutorial?

    -The purpose of the tutorial is to teach how to create basic 2D eight-directional movement with animations for a game in Scratch.

  • Why is the Scratch cat sprite used in the tutorial?

    -The Scratch cat sprite is used because it already comes with movement animations, making it a simple and convenient choice for demonstration.

  • How does the tutorial handle movement using both arrow keys and WASD keys?

    -The tutorial sets up an 'if' condition to check if either the arrow keys or the corresponding WASD keys are pressed, allowing movement to be controlled with both sets of keys.

  • Why does the tutorial use X and Y coordinates for movement instead of built-in Scratch movement blocks?

    -X and Y coordinates offer more control over movement, allowing for finer adjustments in speed and direction. The built-in movement block can be limited in certain scenarios, so using X and Y provides better customization.

  • What is the significance of setting the rotation style to 'left-right' in Scratch?

    -Setting the rotation style to 'left-right' ensures that the sprite only rotates along the horizontal axis, preventing unwanted full rotations when moving left or right.

  • How does the tutorial handle animation switching when the sprite moves?

    -The tutorial creates a custom block called 'get frame' which handles switching the sprite's costume based on the movement direction and timing. This allows for smooth animation transitions as the sprite moves.

  • Why does the tutorial use the 'mod' operator in the costume-switching logic?

    -The 'mod' operator ensures that the animation cycles through a set number of frames (costumes) without going beyond the number of available frames. It resets the costume back to the first frame once the last one is reached.

  • What is the purpose of the 'idle' animation in the tutorial?

    -The 'idle' animation is used to show a static pose when no keys are being pressed. It prevents the sprite from continuing its movement animation when the player is not providing any input.

  • How does the tutorial determine when to stop the animation and switch to the idle pose?

    -The tutorial uses a variable called 'key sensing' to track if any movement keys are pressed. When no keys are pressed, the 'key sensing' variable is set to zero, which triggers the idle animation.

  • What problem is solved by using 'no screen refresh' in the custom block?

    -'No screen refresh' ensures that the animations run smoothly and instantly without waiting for a tick or screen update, allowing for quick costume changes in the sprite's movement.

Outlines

00:00

👾 Introduction to Eight-Directional Movement

The creator introduces a Scratch tutorial focused on creating 2D eight-directional movement with animations. They refer to a previous video on basic movement and discuss how this tutorial is a revamped version with added features. The tutorial will use a Scratch cat sprite to demonstrate movement animations and walk the user through setting up the system for such animations. The instructions include duplicating costumes, setting directions, and using basic movement functions in Scratch.

05:01

🎮 Setting Up Directional Movement

In this section, the tutorial dives into setting up the core system for movement. The creator explains how to program movement using arrow keys or 'WASD' for directional control. Instead of using pre-built movement blocks, the tutorial opts for a custom approach with X and Y planes for better flexibility. It covers details like adjusting movement speed using numerical values and ensuring the character moves smoothly in different directions with consistent speeds.

10:02

🎨 Adding Basic Animations

This part explains how to incorporate animations into the movement system. The creator introduces the concept of 'rotation style' to ensure smooth left and right transitions for the sprite. They also explain how to set the sprite’s facing direction based on movement inputs and how to switch between different costumes for animated movement. Key coding concepts such as defining blocks and managing frames for fluid animations are introduced.

15:04

🧩 Advanced Costume Animations

In this section, the tutorial goes deeper into the animation process by creating custom blocks and defining a frame-based system to manage costume switches. The creator describes how to use variables and operations like 'mod' to limit the number of frames and switch between them continuously. They also debug and optimize the animation flow, ensuring the sprite moves smoothly through various costumes.

🔧 Idle Animation and Frame Sensing

This section tackles how to create an idle animation when the character is not moving. The tutorial guides users through setting up conditions where the animation stops when movement keys aren’t pressed, and the sprite returns to an idle costume. The creator explains how to sense when no keys are pressed and adjust frames accordingly, finalizing the tutorial with a robust movement and animation system for the sprite.

Mindmap

Keywords

💡Eight directional movement

This concept refers to the ability to move a character in eight different directions (up, down, left, right, and diagonals) in a 2D plane. In the video, the creator explains how to program this type of movement using both arrow keys and the W, A, S, D keys, making the sprite respond to the user's input.

💡Sprite

A sprite is a 2D image or animation used in video games and programs like Scratch to represent characters, objects, or other elements. In this tutorial, the default 'cat' sprite is used, and its movements and animations are controlled as part of the eight-directional movement system.

💡Costumes

Costumes in Scratch refer to different visual appearances of a sprite. They can represent different animations or states of a character. In the tutorial, the creator uses different costumes to show how to animate a sprite's movement by switching between them as the sprite moves in various directions.

💡X and Y plane

The X and Y plane refers to the horizontal and vertical axes in a 2D space. X controls left and right movement, while Y controls up and down movement. The tutorial explains how to adjust the X and Y coordinates to create smooth directional movement for the sprite.

💡Forever loop

A forever loop is a control structure in programming that continuously repeats the code inside it. In the video, the creator places the movement and animation code inside a forever loop to ensure that the sprite’s movement and animations are constantly checked and updated during gameplay.

💡Rotation style

The rotation style in Scratch determines how a sprite rotates when moving. The tutorial uses the 'left and right' rotation style, which restricts the sprite's rotation to horizontal movement (facing left or right), avoiding full circular rotation which could disrupt the animation.

💡Point in direction

This command in Scratch allows a sprite to face a specific direction based on degrees. In the tutorial, the creator uses 'point in direction 90' for the right movement and 'point in direction -90' for the left movement to ensure the sprite faces the correct way when moving.

💡Frame

In animation, a frame represents a single image in a sequence of images that make up an animation. The tutorial creates a 'frame' variable that helps manage the switching between different sprite costumes, allowing smooth transitions between movements.

💡Mod block

The mod block in Scratch calculates the remainder of a division. In the video, it is used to cycle through the sprite's costumes without exceeding the number of available costumes. This ensures that the animation loops back to the first frame after reaching the last one.

💡Idle animation

An idle animation is the default state or action a character performs when not in motion. In the tutorial, the creator sets up an idle animation to display a specific costume when no movement keys are pressed, making the sprite appear to rest when not moving.

Highlights

Introduction to basic 2D eight-directional movement and animation for Scratch games.

Explanation of the importance of sprite direction and movement using Scratch's built-in cat sprite.

Setting up WASD and arrow keys for movement with Scratch’s sensing and operator blocks.

Using x and y plane for movement in Scratch rather than the standard movement blocks for greater control.

Introduction to adjusting movement speed by modifying the numerical value in x and y changes.

Implementation of rotation style to keep the sprite facing left and right based on movement.

Explaining how to create animations that switch depending on movement direction.

Creating a custom block ('get frame') to handle costume changes for sprite animations.

Using the 'mod' operator to cycle between different costumes for animation based on movement.

Introduction to frame variables for controlling animation speed without delays.

Implementing idle animations for when the character is not moving.

Optimization tips to ensure animations only run when a movement key is pressed.

Explanation of complex logic using operators to detect whether a key is pressed and control animations accordingly.

Final optimization to ensure the character returns to an idle state when no movement key is pressed.

Encouragement for beginner Scratchers to experiment with more advanced concepts like key sensing and frame manipulation.

Transcripts

play00:00

yo what's popping as i welcome back to

play00:02

another scratch tutorial today i'm going

play00:04

to be showing you something pretty cool

play00:05

pretty useful pretty helpful in a few

play00:08

types of games you could make today i'm

play00:09

going to be showing you some basic 2d uh

play00:12

eight directional movement with

play00:14

animations now if you remember a while

play00:16

back maybe a year ago i actually don't

play00:18

know i didn't check the date a while

play00:19

back i made a video on basic 2d uh

play00:23

eight directional

play00:24

you know movements

play00:26

and i thought i'd like to revamp that in

play00:28

this tutorial while also adding

play00:29

something new to it so that's what we're

play00:31

going to be doing and that's what we're

play00:32

going to be going over how to do today

play00:34

so basically what you're going to need

play00:36

is you're going to need a sprite now i'm

play00:37

just going to use the cat sprite since

play00:39

it has you know

play00:41

it has its movement animations right but

play00:43

let's say you wanted some more so

play00:46

let's say you want a little bit more so

play00:47

what i'll do is i'll actually duplicate

play00:49

this and then i'll make so this will be

play00:50

the final movement then this movement

play00:52

needs to be slightly less

play00:55

it's not supposed to look good it's not

play00:57

gonna look good i'm just doing it to

play00:58

show you what you can do so i'm just

play01:00

gonna have three costumes okay cool so

play01:03

you just have your costumes you don't

play01:04

need to worry about having them face the

play01:06

directions you need to you just need one

play01:07

direction and this is on

play01:10

you'll see you'll see just have one

play01:11

direction usually this is the way you do

play01:13

it in the 90 degree form in the 90

play01:15

degree angle just what this is at right

play01:16

now because every sprite on by itself is

play01:18

90 degrees when it starts off so just

play01:20

have your character facing this way uh

play01:22

yeah just have a facing that way and you

play01:24

should be pretty good so what we're

play01:27

going to do now is we're going to set up

play01:28

the basic system so i'm just going to

play01:29

call this

play01:30

cat lemon i'm not going to let him out

play01:32

scratch cat lull

play01:33

and what we'll do is we will uh first of

play01:36

all let me name this to basic move basic

play01:39

oh my goodness now what we'll do is i

play01:41

will grab a green flag clicked and i'll

play01:43

zoom in so you can see what's going on a

play01:45

little bit better

play01:46

and i will also move my camera

play01:49

now we will do is we will put the

play01:51

forever loop right here just like that

play01:53

and now we will set up our systems for

play01:55

movements so what i'm going to do is

play01:56

grab an if statement and then i'm going

play01:58

to grab an and uh or and what this is

play02:01

going to be is i'm going to going to let

play02:02

you use either the arrow keys or the wsd

play02:05

to move around so one thing we'll do is

play02:07

go to operator sensing and grab our key

play02:09

space and change the space to an up

play02:11

arrow duplicate it put it in the second

play02:13

half and the wasd

play02:16

variation of an up arrow is the w key so

play02:18

i'll use the w key

play02:20

now i'm just going to duplicate this and

play02:21

put it right underneath

play02:23

and i'm going to do the down arrow and

play02:25

the corresponding is s

play02:27

and then we'll do a

play02:30

right arrow and the corresponding is a d

play02:33

and then we will do left error which the

play02:35

corresponding is an a

play02:37

now we're not going to be using the

play02:39

movement key in motion we're not going

play02:41

to be using this movement key this

play02:43

doesn't work very well well it does for

play02:45

its own things but

play02:46

we can do it in a much

play02:48

easier way here by using this x and y on

play02:50

an x and y plane you have up and down

play02:52

which is your y plane and your left and

play02:54

right which is your x plane so we're

play02:56

moving up and down so we know we need to

play02:57

add a y and if we're moving up the

play02:59

higher up you go the uh bigger the

play03:01

number gets and the lower it goes

play03:04

the lower it gets the more down it goes

play03:06

the lower it gets higher up the higher

play03:07

it goes so since we're going up we're

play03:08

gonna change our y by a three you can

play03:10

change that to whatever you want

play03:11

depending on how big this number is it's

play03:13

how fast you'll go so the bigger the

play03:15

number is the faster the sprite will

play03:16

move the lower the number is the slower

play03:17

the number will move or the slower the

play03:19

spiral if you get it

play03:21

so now if we're doing the opposite going

play03:23

down i'm going to duplicate this and

play03:24

we're going to set this to a negative 3.

play03:26

now you want to keep these numbers the

play03:27

same unless you intend on having a

play03:29

character moving backwards be slower

play03:31

than going forward so if you have them

play03:33

as an equal number just with a

play03:35

a

play03:36

negative and a not negative you'll be

play03:38

moving the same direction at the same

play03:40

speed or different directions at the

play03:42

same speed now for right and left again

play03:44

left and right is an x so we'll grab a

play03:46

change x so moving right so the further

play03:49

right that you move

play03:51

the greater the number will be so

play03:53

this way

play03:55

this way the greater the the further

play03:56

this way it's going if your sprite's

play03:58

going this way the number will increase

play04:01

if it's going this way the number will

play04:02

decrease so since we're going right or

play04:04

this way we need to increase our x by

play04:07

three keeping this number the same here

play04:08

if you change one of these numbers i

play04:09

highly recommend changing all of them to

play04:11

match and then going left since that's

play04:13

the opposite of right negative three

play04:16

now if you'll see we have a very basic

play04:18

you can use wasd to move around or you

play04:20

can use your arrow keys to move around

play04:22

now here's our basic basic movement

play04:25

system now this is where you want it to

play04:26

end you can stop watching here but if

play04:28

you want to add some animations and have

play04:29

them switch back and forth when you're

play04:30

moving that's what we'll get to right

play04:32

now

play04:33

so

play04:35

what we're going to need to do

play04:37

is we are going to want to start by

play04:38

setting its rotation style to left and

play04:41

right in this forever loop what that

play04:43

means is so if we check our rotation

play04:45

right now you see if i move this

play04:47

direction we move in a circle which is

play04:48

not what we're going to want to

play04:50

have happen if we set our rotation

play04:52

styles left and right we won't move

play04:54

until we click in the other direction it

play04:56

just sets us going left and right see

play04:58

how we don't uh start turning until we

play05:01

hit a 0 or 180 which is what we want so

play05:04

put that all back up in there

play05:06

stop it there we go and now what we will

play05:08

do

play05:09

is we can see

play05:13

that nothing happens as of now but what

play05:15

we need to do is we need to base this

play05:16

off of our left and right movements

play05:18

since our rotation styles is on a left

play05:20

and right plane we are going to want to

play05:22

change which direction we're facing

play05:23

based off of that left and right system

play05:25

so when we press right which is this way

play05:28

that's a 90 degree angle you can tell

play05:30

because he's facing right and the

play05:31

direction is already at 90. so we will

play05:34

do is we'll grab this point in direction

play05:36

on the right arrow point in direction

play05:38

90. and now for left you're going to

play05:40

want to do the opposite the way you can

play05:41

check this is by clicking on this

play05:42

direction and moving it directly to the

play05:44

other side and seeing that it is a

play05:45

negative 90. so you'll set this to

play05:48

negative 90. so when you start now

play05:51

you'll see

play05:52

that

play05:53

depending on which direction you're

play05:55

moving the cat will change directions

play05:57

as well

play05:58

so great that's just what we want now

play06:00

let's set up the actual animation

play06:02

process

play06:03

so the way this is going to work this is

play06:04

going to get a little complex so if

play06:05

you're someone who's new to scratch you

play06:07

might not understand this but that's

play06:09

perfectly okay i'll try to explain to

play06:10

the best of my ability this is something

play06:12

generally speaking more complex than

play06:15

what most beginners would be doing so

play06:17

we're going to do is we're going to make

play06:18

a block and now what a block is is

play06:20

basically so i'm just going to name this

play06:23

block get frame

play06:25

okay and we're going to run it without a

play06:26

screen refresh which basically means

play06:28

that it's not going to wait for a tick

play06:29

to happen it's going to constantly

play06:30

happen very very quickly

play06:33

so you'll get this big block right here

play06:35

think of this block as like a clicked as

play06:37

green flag right think of this define

play06:39

block as being pretty much everything in

play06:41

the events tab right it's another one of

play06:44

these

play06:46

right so what you could do technically

play06:48

is you could have this

play06:49

as your block and now every single time

play06:52

you call this block

play06:54

this will play

play06:56

so if i do this for example

play06:59

and put this in a forever loop it will

play07:00

forever get frame and getting frame is

play07:03

this so when we start it'll still do the

play07:05

same thing

play07:06

now that's not what we're going to be

play07:07

using this for

play07:09

what we're going to do is you're going

play07:10

to do

play07:12

[Music]

play07:14

is we are going to make a variable i'm

play07:16

just going to take the variable that

play07:17

comes with scratch it's the one that's

play07:18

called my variable and just name it

play07:20

frame

play07:21

okay

play07:22

and now what i'm going to do is on the

play07:23

green flag is click i'm going to set the

play07:25

frame to zero

play07:27

and now

play07:28

what's going to happen is we're going to

play07:30

figure out how much time we want in

play07:33

between

play07:34

our uh frames in between our costumes

play07:37

that the cat is going to be switching

play07:39

so

play07:40

what we will do is we will want to on

play07:43

every single time it runs this because a

play07:46

forever loop it'll run this and then

play07:47

i'll do it again so at the beginning of

play07:49

every single time we're going to want to

play07:50

change our frame by specific number so

play07:52

what we're going to have it do is on

play07:54

every time that it moves into a

play07:57

table of one meaning one two three four

play07:59

five continuing it will switch the

play08:01

costume so what we can do is we can set

play08:04

this to something like 0.3 just as a

play08:06

base example and now what will happen is

play08:09

it will change by 0.3 to 0.6 to 0.9 to

play08:11

1.2 and now it's increased by one and

play08:13

then it'll change the frame so it's a

play08:15

way to change

play08:17

our speed without having to have a

play08:19

weight variable in it because if you

play08:21

were to have a weight

play08:22

control block because if you ever you

play08:24

would have a weight it would wait

play08:26

and then

play08:28

it would let you move a little bit which

play08:29

would just cause a lot of

play08:31

issues which would not be very good so

play08:33

by doing it like this what we can do

play08:36

is i'm actually gonna put the set

play08:37

rotation style

play08:39

right next to right in the gift frame

play08:42

and then what we will do is we will

play08:44

uh switch our costume

play08:47

and now here's what we're going to do

play08:48

we're going to run a little bit of uh

play08:50

code to figure out which costume to be

play08:53

switching to and this is the part where

play08:54

it can get a little bit complex

play08:56

excuse me i had to sneeze

play08:58

so

play08:59

what we will do is we will go to our

play09:00

operators tab and we are you seeing

play09:03

these flies there are these two flies in

play09:04

my office right now you seen this guy

play09:06

look at this guy

play09:07

this guy's just chilling hold up i'm

play09:09

gonna have to get rid of these guys real

play09:10

quick

play09:10

that's what i call fly genocide

play09:13

continuing what we will do

play09:16

is we will come to our operators tab and

play09:18

grab this plus block and we are going to

play09:20

do a one

play09:22

in this first bubble then what you'll do

play09:24

is you'll grab this mod block

play09:27

now if you don't know what this mod

play09:29

block does i didn't know what it did for

play09:31

the longest time either so what we're

play09:33

going to do is we're going to put frame

play09:34

variable in the first time and then

play09:35

we're going to put

play09:37

three in the second one now the reason

play09:39

why we're doing this is you will see

play09:41

here

play09:42

we have three costumes if you have more

play09:44

then this number will change but see how

play09:45

i have three so i put three if you had

play09:48

16 or 43 or 976 that's what you would

play09:51

put in this block and what that will do

play09:54

is it will make you not go past that

play09:57

right so what it will do is it'll check

play09:59

you'll go so let's say you had more than

play10:00

more than this right let's say that you

play10:02

had a

play10:03

just did like that okay what it would do

play10:04

is it run through this costume then this

play10:07

one then this one but since the mod is

play10:08

there it would not let you go past this

play10:11

which means it put you right back at one

play10:12

and that you keep doing this

play10:15

instead of ever getting to that four

play10:17

which is good which is what we want

play10:19

so by doing that everything in theory

play10:21

should go according to plan the only

play10:24

thing we'll need to do obviously

play10:26

is run the get frame right underneath

play10:29

that so let's take a look if we have any

play10:30

issues we can easily go through and fix

play10:32

them let's take a look okay what we're

play10:34

seeing here is that we're instantly

play10:36

constantly

play10:38

running this frame and you'll see that

play10:39

it is actually broadcasting that last

play10:43

sprite so if we just set that mod to two

play10:45

instead of three meaning one less than

play10:46

if we wanted to you'll see that it is

play10:48

playing the three costumes we wanted to

play10:50

do so that's what the issue was with the

play10:52

animation there and since we had it on

play10:54

three it was technically playing all of

play10:55

them which means it plays one more than

play10:57

what every number you put in so if you

play10:58

put in two it'll put it at it'll

play10:59

actually go to costume three and so on

play11:01

and so forth very easy fix now we need

play11:03

to fix the issue of why it is constantly

play11:06

doing this which is really easy that's

play11:08

because it is running before we actually

play11:09

press any arrows and obviously we only

play11:11

want the animation to run if we are

play11:13

moving so we'll do is we'll just put

play11:15

this block in each iteration of us ever

play11:18

pressing a key so now what we will see

play11:20

is that when we start our game

play11:22

nothing happens

play11:24

but when we start moving is when

play11:27

we will have the animation play and when

play11:29

you let go it'll stop playing the

play11:30

animation now one last thing you might

play11:32

notice is that obviously if we look here

play11:34

we don't want him to stop there we want

play11:36

him to have an idle pose right we want

play11:38

him to have this idle

play11:40

you know costume that it switches to

play11:42

right or maybe we want this to be its

play11:44

idle animation right we want to idle and

play11:46

sit on this for some reason i don't know

play11:48

why you would but let's just say you do

play11:50

you want it to idle on your fourth

play11:53

animation how do we go about doing that

play11:55

it's actually very easy

play11:57

so what we'll want to do is something

play11:58

very basic basically all we're going to

play12:00

do is underneath our define we are going

play12:02

to come to our controls and grab it if

play12:04

else and in this if else you're going to

play12:06

run a greater than and we're going to

play12:08

check if our frame is greater than zero

play12:11

and if it is we will run the bit of code

play12:14

we already had created and if not we're

play12:16

going to switch our costume to whatever

play12:18

our idle thing is which in our case is

play12:19

this weird costume four

play12:22

you obviously set that to something

play12:24

better

play12:25

but you know

play12:27

this is just how we're rolling right now

play12:29

so now we need to actually set up a

play12:31

system for it to be zero because if it's

play12:32

zero then it'll be this costume if it's

play12:34

greater than zero it'll do the

play12:36

animations so how do we make it to the

play12:39

point where it's zero if it's constantly

play12:41

changing

play12:42

so what we're going to do is we're going

play12:43

to mess around with our ability of

play12:46

sensing whether or not keys are pressed

play12:47

the first thing we're going to want to

play12:48

do is we're only going to want to change

play12:50

our frame when we are again pressing

play12:54

a button and make sure you put this

play12:56

change above the get frame so that the

play12:58

number changes before you try to get the

play13:01

frame

play13:03

great now what we're going to need to do

play13:05

is we are going to need to run

play13:08

something a little special

play13:10

what we are going to do is we are going

play13:11

to set and we're going to make a new

play13:12

variable and we're going to call this

play13:14

key sensing is what i'm going to call it

play13:16

you can call it whatever you'd like i'm

play13:17

going to call it key sensing and now we

play13:20

are going to start right here we're

play13:22

going to set our key sensing to

play13:25

a minus

play13:27

block and what we're going to do is

play13:28

we're going to

play13:29

check i'm actually going to run for

play13:31

these since we have four possible

play13:32

directions we can go on by pressing the

play13:34

keys we are going to

play13:37

run an or

play13:39

and then we are going to do

play13:40

w

play13:42

or up arrow and we're going to put it in

play13:43

here just like this

play13:45

and again if you're not using both of

play13:46

these you'll only use whichever one

play13:48

you're using obviously whichever one is

play13:52

your you know

play13:53

ability of movement

play13:55

so we're going to set it like this

play13:58

and then we're going to do

play13:59

or

play14:01

a

play14:01

down

play14:03

an s

play14:05

okay we're going to duplicate this again

play14:06

put it in here

play14:09

we are going to do a right or a d

play14:13

and in this final one we are going to do

play14:16

a left

play14:17

or an a

play14:20

so

play14:20

we will set it to any of these now what

play14:23

we'll see is when we start

play14:25

so we run the game and if i press up and

play14:28

left we get two if i press up and right

play14:32

i get two if i press down and up i get

play14:35

two if i press down and right or left i

play14:38

get two if i press down and right i get

play14:40

two if i press a

play14:43

and left i get two if i press d you see

play14:46

pretty much just mess around and start

play14:48

spamming the keys different formations

play14:50

you'll see that none of them

play14:52

can get to zero which is exactly what we

play14:54

want and the only way it gets to zero is

play14:56

if you let go of the keys entirely

play14:58

that's perfect so by switching all of

play15:00

our minus symbols to addition symbols or

play15:03

plus symbols we got rid of the problem

play15:05

entirely which is exactly what we want

play15:08

now right underneath that we are going

play15:09

to want an if else statement so we'll

play15:11

grab an fsl statement and we'll put it

play15:12

right underneath our key sensing and now

play15:15

what we will do is we grab an equal

play15:16

symbol and we will check if our key

play15:18

sensing is equal to zero

play15:20

if it is we will set our frame to zero

play15:24

and now we will do is we will put our

play15:26

old code in this else statement and now

play15:28

what you will see is we are going to

play15:30

have an issue but when we play the game

play15:33

we move right just as we're supposed to

play15:35

all good like that but when we let go it

play15:37

still doesn't go to our idle costume now

play15:39

why is that that's very easy that's

play15:41

because we are only catching the frame

play15:44

if we're moving so if we remove this and

play15:47

put it back where we originally had it

play15:48

which is right here

play15:50

and then get rid of all of the other

play15:52

get frame blocks that we put in the

play15:54

other ones

play15:56

now you will see that when we play our

play15:57

game

play15:58

we're idle when the key is zero and as

play16:00

we move the animations are playing

play16:03

and then when i let go

play16:05

we go to our random idol animation so

play16:08

that is how you go about setting up

play16:09

something like that i'm gonna leave my

play16:11

episode here thank you all so much for

play16:13

watching if you liked it like it if you

play16:14

didn't like it like it anyways because i

play16:15

hope this helped out some early

play16:16

scratchers in their journey while you're

play16:18

right i want to subscribe to the channel

play16:19

video account that helped me out a lot

play16:20

but thank you so much for watching i'll

play16:21

see you on the next one

play16:23

peace

play16:28

[Music]

Rate This

5.0 / 5 (0 votes)

相关标签
Scratch TutorialGame Development2D AnimationEight-Directional MovementCoding for BeginnersWASD ControlsMovement AnimationsGame MechanicsBasic CodingSprite Animation
您是否需要英文摘要?