Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(2 edits)

That's literally the idea.

I'd go further and create a camera object (even if you are in 2D) so you can track the position of your viewport. So anything you render should be positioned by it's local position + the opposite of your camera position. 

For instance, let's say you have an enemy sitting on position X = 2000, Y = 0. If you're in 1080p resolution, that enemy is offscreen if your camera is at position 0,0. Once you move your camera more than 80 pixels forward (let's say 81 on X), that enemy starts to become visible on the right side of your screen, because it's position is: EnemyPosition - CameraPosition, 2000 - 81 = 1919, so you see the enemy's first pixel.

The reason why you should create your own camera even in 2D (if your engine does not already provide one) is scalability. Maybe you want to scroll on both axis at some point? Or maybe you want to scroll to a certain part of your map and then go back to the player location just for a cutscene? For all that you will be thankful to have a dedicated module like the 2D Camera.