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.
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.
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.
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.
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.
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.
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.
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!
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.
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?
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.
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.
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:
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.