Game Design 2: Blogpost #1, Paralaxing backgrounds
|
For this blog post I will be writing about the code I have written for the looping paralaxing background in our game called Behemoth. My name is Jonathan Berggren, I am part of group Siren which is a group of students at Uppsala University, Campus Gotland. I am the only programmer in our group. For our game we want to simulate movement of the ship by making the background continuously scroll to the left. The code that is used for this is quite simple, it works by moving the image to the left at a variable speed that is changed for each different background using the code, the speed is also multiplied with a built-in function called Time.fixedDeltaTime which makes sure that the speed is consistent even if the game runs at a different amount of frames per second. It then returns the image to its original position once it has fully scrolled past the screen. The image is also doubled with a second copy placed right after it so that there is no empty space after the right edge of the image has passed the right side of the screen but has not yet passed the left side of the screen. This same code is used on multiple layers of backgrounds with different speeds applied to them which creates a sort of paralax effect making the slower background appear to be further away than the faster moving ones. The ones in front are transparent so that the backgrounds behind it are visible which also makes it feel even more like glass or crystals to match with the ship and enemies in the game. The paralaxing created what I consider a very aesthetically pleasing look which cannot be properly expressed using a still image however the image bellow is a snapshot of what the game looks like in action using placeholder graphics. Later on this same code will be used for foreground images aswell, we plan to have clouds that will appear to be moving across the screen very close to it just behind the UI of the game in front of the ship and enemies. |
