Tuesday 11 August 2015

Week 9 (11 Aug)

This week we discussed scrolling games.  Such games are particularly important for platform based games which many students are familiar with.  We had a demonstration of a great "potato" run game and then discussed the basics of scrolling in Scratch.  The key concepts are:
1) a backgound is not used, instead a whole screen is used as a sprite that can be moved
2) the player is basically stationary, but that the screen sprite moves to the left or right
3) multiple scren sprites can be used to may a very long scrolling game, but you need to be carful to match the items and color of each screen sprite used

The basic process is demonstarted below that was shown to the stduents this week.  Students were actively involved with many starting , and some completing a basic game in under an hour.  We even had someone scrooling up and down !!!.  Keep going and let me know what your create .  Please post comments.
Scrolling game concepts.  See Figure 1,2 and 3 for an outline to creat a basic scrolling game.  I have used the Cat and changed the costume to make him look like he is moving , but only when the arrow keys are pressed.  Create a ScrollX variable.  This is used to set the current location of the screen sprite.  Change the ScrollX variable by a NEGACTIVE number when moving to the right and a POSITIVE number when moving to the left
Figure 1: Sprite 1 (The cat or other object moving through the scene).  The blocks are shown to the right.  

Figure 2 shows the Screen Sprite and the blocks required in this sprite.  By setting the x-position of the screen sprite to ScrollX, the Screen Sprite moves in the OPPOSITE direction to the direction the arrow key is pressed !!  This gives the illusion that the cat is moving.
Figure 2.  Left most Screen Sprite (Sprite4) and the blocks required in this sprite.  
Figure 3 shows the 2nd Screen Sprite (Sprite3) and the blocks required in this sprite.  In this code 480 is added to the ScrollX value.  Note the 480=2*240, which is the entire with of the screen.  So when the ScrollX value reaches say -490 (because you pushed the right array key many times), the Sprite3 is now centered at x=-490 + 480 = -10.  This is on the screen and very near the enter, so the 2nd Screen Sprite (Sprite3) is now in the center of the screen.  We can keep repeating this by adding more screens.  I will think of an easy way to explain how these screen can be looped around to may the game appear to be infinite and get back to you.  An example of this Scrolling example is shown as an animation in Figure 4

Figure 3:  Screen Sprite #2 (Sprite3) and the blocks required in this sprite.  


Figure 4:  Animation of the Cat showing how Scrolling works.  Check out the ScrollX number in the top left and how each Screensprte seemlessly moves across.

No comments:

Post a Comment