"> ");
100%
LESSONS & TOPICS

Sprite Movement With Mouse

Sprite Movement With Mouse

 

Video – Sprite Movement With Mouse

 

#accordions-600{display: none;}
#accordions-600 {
text-align: left;
}
#accordions-600{
background: url() repeat scroll 0 0;
padding: 0;
}
#accordions-600 .accordions-head{
background:rgba(129,215,66, 1) none repeat scroll 0 0;
margin:1px;
padding:10px;
}
#accordions-600 .accordions-head-title{
color:#ffffff;
font-size:14px;
font-family:;
}
#accordions-600 .accordions-head-title-toogle{
color:#ffffff;
font-size:14px;
}
#accordions-600 .accordions-head:hover .accordions-head-title{
color:#000;
}
#accordions-600 .ui-state-active{
background: #4b8fe3;
}
#accordions-600 .accordion-content{
background:rgba(255,255,255,1) none repeat scroll 0 0;
color:#333333;
font-size:13px;
font-family:;
margin:0;
padding:10px;
}
#accordions-600 .accordion-icons{
color:#565656;
font-size:16px;
}
#accordions-600 .accordions-head:hover .accordion-icons{
color:#999;
}
#accordions-600{}
#accordions-600 .accordions-head{}
#accordions-600 .accordion-content{}

Video Transcript

Let’s begin programming by creating a script that defines the monkey’s behavior.

We will program the monkey to move along with the mouse of the game player.

So, follow the steps below:

Step 1: Open the Scratch application

Step 2: Delete the cat from your screen.

Step 3: Enter the Monkey2 character from Scratch’s library into your project.

Step 4: Change the name of the object to “monkey”.

Step 5: We want the monkey’s move to begin from the moment the game starts.

This can happen by pressing the green flag. From the commands palette “Events”, locate first and then drag with your mouse the command “when the green flag is clicked” and drop it in the space of the scripts’ area.

Step 6: Of course, the object’s movement is defined by a command on the “Motion” palette.

Open this palette and look all the commands, one after the other.

You will find the command “Go to mouse pointer”.

Drag this command to the script area and join it with the previous command, as in a puzzle.

Now, try your script.

The monkey moves to where you have your mouse pointer: the green flag that you have just clicked on.

The movement of the mouse pointer does not mean a corresponding movement of the object. Some change should be made.

Step 8: We want the “Go to mouse pointer” command to be repeated continuously throughout the game process.

The key word here is the word “repeated”. We should use a repeat block.

Let’s listen to what the specialist has to say about this issue.

Often, we want the commands created in Scratch, but also in any programming language, to be running repeatedly.

The existing commands in Scratch that repeat the commands they contain are the following:

  • Repeat a specific number of iterations
  • Repeat until an event occurs
  • Repeat forever

The command “forever” repeats the enclosed commands for the entire duration of the game.

This command, like any of the commands just mentioned, may contain 1, 2 or more other commands executed in order, one after the other.

Once the commands finish, they run again from scratch.

In the command “forever” this continues until the end of the game.

The command “forever” is exactly what we need in this game. We will use this command.

So, drag the “forever” command to the script area and use it this way.

Now, run your project and try the result.

Congratulations! You have just created your first project in Scratch!