How to scroll smoothly from background1.png to background2.png by resetting player position to x0,y0 when in background2 and so on?


Thank you Naith!

I understood what mistake I made while reading the code:

If hopefully I’m not wrong that’s what it is:

Camera.XPosition += ((ScrollingLeft ? -Camera.Velocity : Camera.Velocity) * (float)DeltaTime);

I did not realise that ( being into an if statement that is always true when !Camera_STILL)
by using the code above the value in Camera.XPosition keeps increasing/decreasing automatically in every iteration, also Camera.XPosition was declared outside the if condition loop so it will not lose its current value.

and then when after various iterations that value reaches 800 or a bigger value (if bigger I guess is slightly bigger and not noticeable during rendering) immediately(that’s why I said not noticeable) the code set the Camera.XPosition, Camera.PrevXPosition to their final position that are fixed values 800,1600,2400,3200… and set Camera_Still and therefore ends the scrolling.

Please let me know and many thanks again!


That is indeed how the scrolling sequence work. :slight_smile:


Perfect! :wink:

Many thanks again mate!

If you know good books or tutorials that you consider useful to learn/improve SDL skillls please let me know :+1:

Or if you want to share some pieces of code please feel free, I learned a lot from your examples.


When I started using, and learning, SDL, I went through tutorials on a site called Lazyfoo. On that site, the author uses SDL only (without any fancy things like OpenGL etc), which is good for beginners.
You can find the tutorials here:

The only thing I’m not the biggest fan of, when it comes to those tutorials, are the code style and structure, but all programmers have their own style and taste. Besides that, they are very good and will teach you a lot.


Hi Naith,

Thank you for your reply,

I know them, I’m actually at chapter 32, the one before was about background scrolling and that’s why I wanted to find out more.
I noticed your style is way better, for example the fact that you use float numbers when it comes to move SDL_Rect objects is brilliant. That’s why If you have useful things to share according to your experience that you consider valuable to learn further from those tutorials please let me know.


Actually, in tutorial 44, Frame Independent Movement, the author use float variables to control the movement of a dot image. :slight_smile:
Also, deltatime is explained in a good and easy way in that tutorial, which is good for those that aren’t that familiar with frame based movement and deltatime. In that tutorial it is also explained why the author doesn’t use frame based movement etc in other tutorials, which is because some floating point errors that might occur, which can only be fixed with vector math.

If you wonder something more about the game you show in the video in your first post, and/or need help with something else in the game you’re making, let me know.


Hi Naith,

Thanks for your reply, it’s good to know lazy foo covers those concepts as well, I will have a look then as soon as I get at the end of his online course!

I guess things I will kindly need to know (if not explained in lazy foo tutorials) are:
jumping, how to throw an object in a direction (like a weapon), and possibly networking would be a plus.
If you kindly know good tutorials or you want to share examples please feel free.
Also what formulas are important in game development that you reckon I should know?
Velocity*DeltaTime applied to movements is crucial like you said to keep a constant speed on different computers…I’m quite sure there are few others that might be worth knowing.

Many thanks again for all your help and time!


To not have this thread filled with other topics besides the scrolling part, it might be best if you start another thread regarding the stuff you need help with, for example the jumping part.
I like to read/view threads on forums that looks clean and focus only on 1 topic, in this case the scrolling part. This might help people coming here that’s having the same issue you had when you first started with your game and by filling the thread with other topics might cause confusion.
So feel free to start a new thread regarding jumping and we’ll take it from there. :slight_smile:

Also, since I, like I said, like clean threads, some of your earlier posts in this thread are filled with code, which is hard to read because of wrong indentation. Do you mind fixing up those posts by surrounding your code with the Preformated text character and then surrounding it all with a Hide Details block?
The Hide Details block can be found in the gear wheel-menu.


Hi Naith,

Thanks for your reply.

I agree with you! I fixed the code above in preformatted text so it’s easier to follow the conversation. (I did not know what I had to click to do that). I have hidden some code as well (other times the hidden feature did not work as expected)

I started another thread so this one will not go off topic!

Many thanks again for all your help! :slight_smile:



I am loading 3 images 1.tif - size 8100X8100, 2.tif - 8100X8100 and 3.tif - 8100X8100.
How can i scroll without key event and also i am able to see only 2 images when scrolling last image does not load.

I am attaching source code here. please correct me if i am wrong anywhere.
Kindly do the needful.


main.cpp (13.7 KB)


Hi there.

By looking at your code, I can see it’s based on my code example that I provided for TheThinker 2 years ago, in this thread.

I get the feeling that you might not be entirely sure exactly what the code does. Is this the case?
If yes, you should ask about the thing(s) you’re unsure about and not just copy-paste the code and expect it to work the way you want.
For example, why have you chosen to use 27 sections (NUM_SECTIONS is set to 27 in your code) when you are planning to only load 3 images/textures?



Thanks for your reply.

I have done that. still working on few feature.

I will touch with you if i need your help.

Many thanks.