Copyright © 2002 Bolton Institute Scrolling Andrew Williams
Copyright © 2002 Bolton Institute scrollh The first example simply scrolls horizontally –Look at screenRect in the program –Read the comments in the program
Copyright © 2002 Bolton Institute scrollv This is the equivalent of scrollh, only with vertical scrolling –Obviously, it is scrolling the “wrong way” –Again, screenRect is the key
Copyright © 2002 Bolton Institute scrollhsprite1 Adding a sprite to the example Although it looks right, it’s actually wrong. The sprite is in screen space and the background scrolls in world space
Copyright © 2002 Bolton Institute scrollhsprite2 This time, although it looks wrong, it is actually correct! –Both background and sprite live in the same coordinate system
Copyright © 2002 Bolton Institute scrollhsprite3 In this version, we move the sprite in an attempt to “keep up with” the background –But is this the right approach?
Copyright © 2002 Bolton Institute scrollhsprite4 This is probably more correct: –The sprite moves in world space –We move the “viewport” on the background as the sprite moves
Copyright © 2002 Bolton Institute scrollhsprite5 If we use this approach, we can place other sprites in world space and wait for our sprite to encounter them
Copyright © 2002 Bolton Institute scrollhsprite6 Simple control of the player’s sprite –Notice particularly the new, more complex approach to keyboard control This fixes the problems we’ve been having with the PS2
Copyright © 2002 Bolton Institute scrollhsprite7 This time there is no automatic movement of the player’s sprite –We move forward using the right-arrow key –Whether this is what you want is up to you
Copyright © 2002 Bolton Institute scrollhsprite8 Random location of the enemies –Look out for srand(...) and rand() The s stands for “seed”