/  8
 
 
SMini
The trick to have the scrolPlatform Sprites. A Platforbackground but it can intThink of the Stage as a viestarts from x = -240 and ereference frame and ignowhen sprites move.The viewable area also do
ShallWeLearn | http:/
ratch Programming Lesson 14ario Game Part 5 – Scrolling Intro
ling platform effect in a Scratch game is to am Sprite is an immobile sprite that looks likeract with other sprites on stage.wable area of an infinitely long strip. This vi
 
nds at x = -240. We will just consider the onee the y-axis for now. The reference frame des not change when sprites move.
/shallwelearn.com
1d multiplea stagewable area-dimensionales not change
 
 
To illustrate how scrolling480.Platform 0:Platform 1:Line them up side by side,area):
Th
Before ScrollingScroll to the right by 120Scroll to the right by 480
ShallWeLearn | http:/
works, let’s use these two platform sprites tstarting from the left edge of the Stage (the,
Whole Strip What
 
/shallwelearn.com
2at each spansviewable
’s Shown on Stage
 
ShallWeLearn | http://shallwelearn.com
3When the game first starts, the red platform’s center is located at x = 0 and takes upspace from x = -240 to x = 240; the green platform’s center is located at x = 480 andtakes up space from x = 240 to x = 720. Both have width of 480.240 – (-240) = 480
width of the red platform sprite720 – 240 = 480
width of the green platform spriteThe orange box represents the Stage and only area inside the orange box is viewable.The Stage is 480 in width (x-axis) and 360 in height (y-axis). Only the x-axis is shownbecause we will only be scrolling left or right.If we let STAGE_WIDTH be a global variable for the width of the Stage, andPLATFORM_INDEX be a local variable of each platform sprite, which specifies wherethe platform is on the strip, then we can represent the starting positions for bothsprites as PLATFORM_INDEX * STAGE_WIDTH ( * is the multiplication sign).STARTING_POSITION
RED
= PLATFORM_INDEX * STAGE_WIDTH = 0 * 480 = 0STARTING_POSITION
GREEN
= PLATFORM_INDEX * STAGE_WIDTH = 1 * 480 = 480

Share & Embed

More from this user

Add a Comment

Characters: ...