Friday, November 22, 2019

game mechanics - How to make a scrolling background


I'm making a Shooter game like "1943" and "Jamestown". I am Using Visual Basic 2010. I was wondering how I would make the background scroll up to simulate moving forward. I would also like it to scroll slightly to the left and right when the player reaches the sides of the screen. Finally, how would I make this efficient? I was thinking about using a animated GIF or making a looping BitMap. Please could someone help me out?



Answer



The backgrounds in Jamestown are not looping bitmaps, because they are always changing from the start of the level to the end.



But if you only need a looping bitmap, and you only need it to loop vertically, the easiest way I know is the following (cross reference with the image below):



  1. Draw the background twice, stacked vertically like on the image below. Of course the image you use must be seamlessly tileable. The red rectangle represents your screen.

  2. Start moving both background instances down. You do this by adding some value to their vertical position each frame.

  3. When they reach the position represented in the image (e.g. when topBackground.Y >= 0), subtract one background height from each of their vertical positions to bring them back to step 1.


  4. Repeat.


    enter image description here





There are more complex ways of handling the problem depending on whether you need to loop horizontally and vertically at the same time, or if you need to zoom and rotate the background. You can use these as reference if needed, although I'm not sure how you'd translate it to your platform:



No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...