Use Scratch 3.0 to Make Scrolling Platformer Game – Key Point Summary Part 2

In the previous post, I explained some confusing points in Griffpatch’s Scrolling Platformer Tutorial Part 1 to Part 5. I will continue explaining some key points in video clips of Part 6 to 10 in this post. If you have watched the video clips of Part 1 to Part 5, you might have understood the structure of scrolling platformer game and felt comfortable to follow the left parts. Let’s start now.

The Sequence of the Blocks are Important

In Part 6 of the video clips, the author solved a bug which occurred when Danger sprite stands right below Platforms sprite. To solve this issue, the author not only separated Danger sprite from Platforms sprite, but also adjusted the sequence of blocks.

Before the adjustment, “Test – Die” block is put at the beginning of “Change Player y by” block to check if Player sprite touches danger. At that moment, the Player sprite just moves along y direction without considering if it touches Platformer sprite or not. Therefore, Player sprite might pass through the surface of Platformer sprite and touch Danger, invoking “Test – Die” condition become true.

In the updated code, “Test – Die” block is called after “Change Player x by” and “Change Player y by” blocks run. At that moment, Player’s position has been adjusted and it will not pass through the Platform. Therefore, it will not collide with the Danger sprite below the Platform.

If you have ever tried to write your own platformer game, those code blocks are really confusing. Understanding how to control the behavior of Player sprite is the most challenging part of platformer game. When to call different blocks or set variable values will affect the final behavior of the Player sprite.

Make the Screen Scroll Smoother

In Part 8, Griffpatch introduced a way to make the screen scroll slower and smoother. That is really useful. You could also set scrolling effect of x direction in the same way. The code also considers the boundary condition where Player walks to the left edge of the map. It “set SCROLL X to 0”. If your game map contains right edge, you should also set a maximum value to SCROLL X.

The Momentum in x and y Direction

In Part 9 of the video clip, the author introduces a way to set momentum in x direction. When absolute value of sx is increasing (sx could be either positive or negative), through multiplying 0.8, its absolute value is reduced. Just use a simple function: (sx + 2) * 0.8 = sx, we could get sx’s maximum value of 8. Therefore, if you keep pressing down Right arrow key, the maximum sx would be 8. The same applies when pressing Left arrow key.

When the user releases Left or Right arrow key, sx decreases until approximately equal to zero and Player stops. The momentum factor determines how fast Player could accelerate or decelerate. The closer the factor is to 1, the faster Player would accelerate and the slower it would decelerate, vice versa. You might tweak the number several times to find a suitable factor. For example, if your platformer game simulates an icy surface, a bigger factor (e.g. 0.92) might be proper. However, if your game simulates water setting, a smaller factor (e.g. 0.7) could be more suitable.

Handling Wall Jumping

In Part 10 of the video clip, the code handles the wall jumping scenario. Wall jumping happens when the Player touches the wall (which is actually part of platform) and presses Up arrow key. The code sets “sx” to simulate a pushing back effect. After that, it sets “in air” to 0, meaning that the Player could jump at that moment. With the method, every time the Player “kicks off” the wall, it could jump, even it is already off the ground.

Please note that in “change x by” block, the code only needs to set “sx” and “in air” values. Once the block sets “in air” to 0, other code in “Tick” block could catch the pressing of Up arrow key and set “sy” to 16, making Player jump along the wall.

When we design platformer game, a common issue is that we could not assign clear responsibility to different blocks, especially to “change x by” and “change y by” blocks. Just keep in mind that “Tick” block runs very fast, so we could adjust x and y in different blocks.

The code to handle wall jumping not only generates a backward pushing force to “kick” against the wall, but also make the Player avoid the extruded edge of the Platforms, as shown in the below image. Without kicking back action, Player might hit the extruded edge and fail to jump onto a higher surface.

That is all for the explanation of Griffpatch’s scrolling platformer game tutorial. The best way to learn is to code by yourself. So take your time to follow the video and develop your first platformer game. Enjoy the coding and have fun!

Note: All the analysis articles are copyright products of Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google photo

You are commenting using your Google 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.