Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to go about side scrolling games?

A topic by Willisthehy created Jan 04, 2024 Views: 232 Replies: 2
Viewing posts 1 to 3

I have the most experience in godot, and python and I want to start a side scrolling game how would one set up the scrolling feature?

My idea would be to set the X variable for the background to a variable and change it based on players position but I'm not sure if this is the best way to go about it

(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.

If you're using Godot then just use the Camera2D node. Make it a child of your Player scene, flick on 'current' and you're off to the races