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

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: http://lazyfoo.net/tutorials/SDL/index.php

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:

Hi

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.

Thanks.

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?

Hi

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.

Hi

I am using 8 cropped images. NUM_SECTIONS = 8. when i do scrolling i am getting jerkies/non smooth scroll.

Each image 6480 width and 1080 height.

How to fix the jerkies problem? Any solution for that?

Do the needful.

Many Thanks

Hard to tell why it’s jerky/non smooth movement, without looking at your code.
Please upload your code to a github or similar and paste the link to it here.

Also, avoid using that big image sizes. Is it possible for you to reduce the size of your images? I’m not saying that the images are the cause of the jerky movement but you should always try to avoid loading big images into memory.

Can i use small width and height images ? Can you suggest the best size of image (width and height ) for very smooth scroll.

Attached source code.main.cpp (21.6 KB)

Kindly do the needful.

Thanks

Yes, you can of course use smaller images and I also recommend doing so. I can’t really suggest an image size since it depends on your needs.
Just to make it clear - when I talk about smaller images, I’m refering to the image sizes in pixels and not in storage sizes (kb/mb).

I couldn’t see anything strange in your current code that could cause stuttering movement. I recommend you to try with smaller images and also try your program/game on another computer to see if the movement is smoother.

Hi Thanks for your reply.

Shall i use image size 1920X1080 instead of 6480X1080 ? Should i get smooth scroll? or need to do below 1920X1080 ?

Looking forward your reply.

HI

What is FPS here 60 or other value? How velocity are calculated ?

Shall i use image size 1920X1080 instead of 6480X1080?

Like I said - I can’t really suggest a good image size for you since it’s all up to you and what your game/program needs.

Should i get smooth scroll?

I don’t know, don’t understand the question.

What is FPS here 60 or other value?

The code you’ve based your code on doesn’t use a fixed FPS but instead uses deltatime to move objects around on the screen / in the window. This means that the FPS isn’t capped to a fixed FPS and the game/program instead has as high FPS as it can be, based on your computer specifications.
If you aren’t familiar with deltatime, you can read about it here:


Learn about implementing it here, and how and why it’s used:
http://lazyfoo.net/tutorials/SDL/44_frame_independent_movement/index.php

If you wants to have an FPS of 60, you’’ either have to enable VSync or implement an FPS limiter. Most monitors has an 60hz update frequency but there’s also monitors with 75-, 120 and even up to 240hz update frequency, so keep that in mind when enabling VSync.
If you want to limit your game/program to 60 FPS (independent on the monitor’s update frequency), you’ll have to implement an FPS limiter that limits your game/program to an update frequency of 60 FPS.
If you want to learn about- and how to implement an FPS limiter, you can read about it here:
http://lazyfoo.net/tutorials/SDL/25_capping_frame_rate/index.php

“How velocity are calculated?”
You have another thread where you are asking about velocity etc and you have gotten multiple answers in that thread. You should ask in that thread instead, since all the answers can be found there.

Hi Naith

I have used 1920x1080 image size. Now i am okay with scroll. its very smooth no stuttering/jerkies.

Thanks for your information.

Regarding velocity i will check with other thread.

Many Thanks.

HI
Thanks for more clarity.

My image scrolling application integrated to hardware (motor) - Digital screen printing. So in this case should i delta time or FPS for image scrolling application.

Since i am getting speed difference between image scroll and motor, if i give velocity 1920 in image scrolling application is it pix/sec or frame/sec? please confirm. thanks

If i give velocity value 1920 in image scroll application and the same value apply for hardware motor in rpm (1920 rpm), both application scroll and motor speed does not match.

Thats why asking should i use FPS or delta time to match the application scrolling speed with motor (rpm).

Looking forward your reply. Many thanks.

Sorry, can’t help you with that.

Hi

Fine. No problem. Now my application based on horizontal scroll it works fine and very smooth scroll, similarly vertical scroll possible with “n” number of images(Cropped images)?

Looking forward your reply.
Many Thanks