Beginner’s Scratch Challenge 12 – Scrolling backgrounds

This week we are exploring a new concept of moving across a landscape like some of the treasure hunting type games such as Super Mario Brothers(SMB). Mario moves through a landscape of dangers and treasures looking for Princess Peach. He must avoid turtles and capture coins in order to keep going and not lose lives and start all over! Here are the notes in PDF:CDA-S5-Challenge_12-Scrolling backgrounds.cda-s5-challenge-12-scrolling-intro

To understand the concept, you must understand that the STAGE is only 480 pixels wide (x goes from -240 to +240). No one SPRITE can be larger than the STAGE and we won’t be able to see a SPRITE that isn’t on the STAGE (ie. it’s x position is less than -240 or greater than +240). So we have to set up a series of SPRITES that extend past the stage and move them across the stage from left to right and under Mario’s feet to make it look like he is moving over the ground from right to left! Get it? It’s tough, but by the end of next week we will have a cool game!cda-s5-challenge-12-scrolling-stage_size

1. We started by downloading an SMB cartoon character from the internet and saving it as an image file (either .png or .jpg) on our desktop or in our personal folder. We used this file to import a new sprite from FILE from the NEW SPRITE area. We then had to make any white background transparent and shrink Mario down to a reasonable size.

2. Next, we drew our own Ground SPRITE using the PAINT NEW SPRITE button. Important!! The sprite must be the full length of the stage!! See the 1st picture above for an example of what the ground sprite could look like. Mine looked like a brick wall, but yours can look like a stone wall or concrete one or some kind of footpath or road.

3. Now we must code our Ground SPRITE! We need to set it’s inital x position to zero and continuously move it in a direction for as long as we are pushing the right or left arrow buttons. To do this we need a new VARIABLE called XPOS. Go to DATA and create this new VARIABLE. See the image below on the bottom the instructions for setting up the initial position of the first ground SPRITE. After you create and code the first one, we can duplicate Ground SPRITE 1 and create Ground SPRITE 2. Be sure that Ground SPRITE 2 has an xpos set to 480 pixels more than Ground SPRITE 1.  cda-s5-challenge-12-scrolling-ground_sprites_1

4. Lastly, for this week, we need to get the Ground SPRITES to move!!

!!IMPORTANT! !Click the little i button on your Ground  SPRITE and see all the information about the SPRITE. Change the rotational direction of the Ground SPRITE to non-rotational. It is a button that looks like a dot.

We will code the Ground SPRITES to move to the left when we press the left arrow key and to the right when we press the right arrow key on our keyboards.  See below: Be careful to program the left arrow key to Point In Direction 90 and the right arrow key to Point In Direction -90. Notice both the Change xpos By commands have different numbers! (-5 and +5) Get these wrong and the SPRITE will not move in the correct direction. Once you have the 1st ground SPRITE working the way you like, duplicate it and all it’s coding. All you have to change in Ground SPRITE 2 is the xpos. It must be set to XPOS +480. If you duplicate that sprite, you must set it’s xpos to XPOS + 960 and so on and so on…cda-s5-challenge-12-scrolling-ground_sprites_2

My original project is on the website. You can log on with your own login name or use our one – CDATHENRY1516 and our password is CDATHENRY and play the game or download it to your computer for next week’s class. Next week will will be coding Mario to jump and to always return to the ground and giving our program a bit of perspective with a mountain in the background. I’ll try adding a coin or two for Mario to jump up and grab! See ye all next week!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s