Today we're going to reveal how to make a basketball game on Scratch! In this tutorial, we will show you how to animate a simple basketball game by utilizing commonly used blocks such as the ones from motion and looks category. The key to this short game is coordination and timing. Every sprite has at least one task and the sequence of when and how these tasks are performed is important.
For the most part, our “wait () seconds” block will take care of the timing part for custom switching and ball passing. The “go to x and y” block should take care of the ball’s whereabouts, and different “switch custom to” block will take care of the overall appearance, gesture, and body language of our humans sprites. And just like in a real basketball game, strategizing the next move is crucial. Hence “broadcast message” and “when I receive message” blocks will help determine whose turn it is to perform.
If you enjoy creating games in Scratch, be sure to check out our live, online, award-winning Scratch coding for kids classes and our game building class for kids - designed by experts from Google, Stanford, and MIT. There's no risk in trying with our free intro session!
See how to make a basketball game on Scratch in simple steps
Scratch for kids is great for making games. Here we'll walk you through 16 steps to making your own fun game.
Step 1: Select sprites and resize
Select the three sprites (Andie, Jamal, and Dorian) plus the ball sprite and manually set their size to 70% for the three players and 40% for the ball.
Step 2: Choose a backdrop
In the Backdrops library under Sports choose the Basketball 2 backdrop.
Step 3: Customize the sprites – delete ball
In the custom tab for each player sprite, remove the ball from their customs. We will use our ball sprite instead. To remove the ball simply click on it and press the backspace key or click on the trash bin icon to delete it.
Step 4: Customize sprites – duplicate and edit
Duplicate Dorian’s custom by selecting dorian-c by right clicking and selecting “duplicate” from the options. Then move his arms up so that we can later use that particular custom to animate his excitement once the team scores. To rotate the arm, click on it, and look for the curved double arrow.
Step 5: Ball sprite’s initial location
We are ready to code. We will start with the ball sprite but first, click on dorian-a custom, and manually position the ball in Dorian’s hands. Then set the ball’s position (x and y points) to always be there when the green flag is clicked. We will also need the ball to stay there for about a second and a half before Dorian passes it to Andie.
Step 6: Ball’s next location
Switch Andie’s custom to andie-a, and manually position the ball to be in his right hand. Only then are we ready to program the ball to be passed (glide) from Dorian to Andie. We do this by changing the x and y points.
Step 7: Make sprite Andie switch hands
The next step is to have Andie show off his skill by switching the ball from one hand to another. We will use the broadcast message block.
Step 8: Broadcast 1st message
Now we need to program Andie’s sprite to do two things: 1. switch the ball to his left hand and 2. Pass the ball to Jamal. This can be done as soon as Andie receives “message1” from the previous step. Furthermore, we will broadcast yet another message (Call it message2), which will trigger the ball to also go from being in Andie’s right hand to being in his left hand.
Step 9: Broadcast 2nd message
Go ahead and test your game. You will notice that Andie now has his left arm raised. This is what we wanted. Manually move the ball to his hand and change the x and y points to reflect that. All there is left to do after at this point is have Andie pass the ball to Jamal.
Step 10: Message2 – What to do
It is time for Jamal to catch the ball. Under Jamal’s customs, select jamal-a so that we can go ahead and position the ball to where his hands are. We will add a .5 second wait time as well as the glide block so that the ball can glide into Jamal’s hands. We also need to prep Jamal for the message2 – he will get into the catching position which is jamal-a custom.
Step 11: Message2, few more steps
Use jamal-c custom for ball throwing, however, edit his arms first. Make his arms appear closer to one another. We did this for Dorian in Step 4. Also, we need Jamal to switch to this custom at the right time, so we’ll add a wait block in between.
Step 12: Prep to score
We are once more going to add on to where we left off with the ball. In this step, we need to position the ball between Jamal’s hands and add another pause, and another “go to” block.
Step 13: The scoring steps
We are not done with the ball just yet but we are to the final steps of ball’s whereabouts. We need to make it look as Jamal is going for the hoop. Position the ball to the top of the basketball hoop, add the glide block, and then position the ball to the bottom of the hoop, and add another glide block. At that point, we need to broadcast another message which will trigger all three player sprites to celebrate by throwing their arms in the air and jumping up and down.
Step 14: Prep to animate excitement
Jamal, Dorian, and Andie will all switch customs when they receive message 3 but Jamal and Dorian will appear if they are jumping up and down. For this, we will use the same concept as we did for the ball – we will manually move the sprites up and down to get the x and y positions in our glide block.
The only thing that should be different is the amount of time the customs will glide for. One second is too long and we want to make the jumping appeal a little more realistic. We will repeat this process for 10 times for both Jamal and Dorian.
Step 15: Keeping customs in line
Test your game. What do we notice? It seems as the last steps of the custom switch stayed there doesn’t it? Which sort of throws off how our sprites behave when we want to see them pass the ball etc. It just does not seem right. This is an easy fix. For each sprite we will use the “when the green flag is clicked” to assign their appropriate customs for a smoother transition.
Step 16: Broadcast 3rd and final message
We need to adjust the customs as each sprite receive the broadcast message. Do this for all sprites under each broadcasted message.
Step 17: Add score variable
All there is missing is the score. Click on Variables, and then click on Make a Variable. Name it Score and leave the radio button checked off for all sprites.
Step 18: Program score using condition and operators
Add two points when the ball lands on the floor. That is the last “glide” block we used for the ball. In our case, that was x=-81 and y=-144. Use the if/then conditional block as well as operation blocks ‘=’ and ‘and’.
Step 19: Reset score
As you test your game, you may have noticed that we keep adding to the score regardless of how many times we start the game over. This is an easy fix. All we need to do is set the score back to zero at the beginning of the game which would be when the green flag is clicked. You can do this under any sprite but we should stick with the ball since the score is added once the ball is on the ground. At this point, you are all set!
The link to this game can be found here!
Make a basketball game on Scratch today
When it comes to animating your game on Scratch, the goal is to make everything look as “real” or as “alive” as possible. In this tutorial, we gave you an idea of how to do just that.
From editing and switching Sprite customs, to broadcasting and receiving messages, and even selecting precise x and y points for the ball to flock to, we have plenty of tools to make even a simple game seem sophisticated and catchy. All that’s needed is an idea and creativity.
Up next, see how to make a clicker game on Scratch or enjoy a free intro to Scratch coding class.
Written by Sandra Dizdarevic, a Create & Learn instructor with 6 years of experience teaching STEM to children in the 3rd through 11th grade. She has an Undergraduate as well as a Masters Degree in Management Information Systems from UNO.