Module 1 Introducing Scratch
Before we start having fun with Scratch we need to know how it works. Don’t worry – it’s not as difficult as you might think, and this first module talks you through the basics you need to know. You can also watch a video tutorial in which Ricky, our games designer and Scratch expert, shows you around the layout and controls.
By the end of this module you’ll have coded and controlled your very own game character! So, take a look at the video, print off your module instructions (if you want to, or just use this site) and let’s get coding…
No Youtube video above? Download it here!
- Getting Started
- Character Blocks
- More Movement
- Basic Animation
- Each time you want to change your sprite, make sure you have the correct sprite selected - this is what it will look like in the control panel.
- This is the scripts panel - This is where we add all the code that tells the game objects what to do.
- The different coloured titles are menus for code controls:
is for code that moves your objects
changes the visual look
We'll use lots of different types of scripts in Shaun's Game Academy. If you want, have a look through now and guess what they do!
At the top of the Game Area you have the controls to start and stop your game.
The green flag starts the game and the red dot stops the game.
- This is the 'Costumes' tab where you can draw game sprites.
- Select ‘Vector Mode’ which makes editing objects easier.
- Draw a box on the center spot using the draw rectangle tool, about the same size as this.
- We now have a new black rectangle, or ‘sprite1’!
- Next select the ‘scripts’ tab and let’s add some scripts to the block.
- Make sure you have ‘sprite1’ selected, and the Scripts tab open.
- Now drag and drop a block from ‘events’.
- Remember that the green flag starts the game playing, so this block starts the scripts working! It’s quite an important first block.
- Now drag a(forever loop) from .
- Drag this into scripts and attach it to the block.
- Now add a block from
and drag it into the loop.
- Click the green flag to test your project.
- The block should whizz off to the right!
So why does this happen?
What these scripts say to do is:
- When the game starts (green flag clicked) move the sprite along the ‘x axis’ (this is left and right directions) by 10 pixels forever, so it will move the block to the right until the game stops.
- Press the green flag to test it: Look! It makes the block zoom off to the right. Whoop!
- Now let’s add controls...
- What we have done is added keyboard controls from the tab in the scripts.
- What the code now says is;
When the green flag is clicked if the left arrow key on the keyboard is pressed - move the sprite left forever and if the right arrow is pressed move sprite right forever!
These character controls are used in simple games. In fact, the legendary game PACMAN uses these very same controls!
WELL DONE! YOU'VE NOW CODED AND CONTROLLED A GAME CHARACTER!
Now it’s time to play test. When you make a game it’s important to keep testing your scripts, so you can spot your mistakes and change things. Feel free to experiment and add up and down controls, too. Experimenting is the best way to learn new scripting skills.
- We’ve made this project ready for you to start dressing the character.
- Here’s a Shaun sprite which has all the animation frames ready to go in the Costumes tab.
- Now we need to line up the animation sprite with the character (box) so that it follows it properly.
We have separate animation sprites to the block character to give us more control over which animation cycle we use. When we add other character functions - such as a jump, for example - we will add other animations to match up with it. We’ll explain this in a bit...
- Make sure you have the 'Character Run Animation' sprite selected.
- Copy the scripts while the 'Character Run Animation' sprite is selected. Take your time to find and check you have the right scripts.
Once you've done that, click the block and the animation sprite should line up with the character block.
Take a look at the picture to see what this should look like.
What the script is saying is:
- When the green flag is pressed, start a loop which will set the position of the animation to the position of the character. This will happen continuously, because it’s in a loop.
- It then checks to see if the left key is pressed, if it is, point left and if the right key is pressed, point right.
At the moment, your sprite moves with the block but it doesn’t animate. Now let’s get the animation moving so Shaun looks like he’s running! We need to tell the animation sprite to change to its other ‘costumes’ so we have to add scripts that tell it to do that:
Here we have added two blocks.
These tell the sprite to go to its next costume and as they are in aloop, they will keep changing to their next costume until the game stops.
When the green flag is pressed, start a loop which will set the position of the animation to the position of the character.
This will happen continuously, because it’s in a loop.
It then checks to see if the left key is pressed, if it is, point left and start the animation facing left.
If the right key is pressed, point right and start the animation facing right.
Now our character will run left and right and the animation will show the character running.
Well done! You've added movement to your game character and completed Module 1.