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
Add a Comment