SDL Window + Image Scrolling

Hi
I am working image scrolling application using SDL 2.0.9. Its works fine as of now.

I need to do 2 things in my application.

  1. SDL window open but not image scrolling started.
  2. Based on time delay image scroll will start.

Attached my source code main.cpp. Kindly do the needful.

main.cpp (28.4 KB)

Many Thanks.

First of all, remove all the code that isn’t used (i.e the code that are commented out). It’s easier to read the code without half of it being commented out.

What exactly in your code isn’t working?

  1. If you want scrolling to occur, simply move the camera to the right, at each update.

  2. If you want to delay the scrolling, have a timer counting up (or down) and when it reaches a certain value, set a bool to true.
    Check the bool and whenever that bool is true, scroll the camera to the right.

Hi Naith

Thanks for the response.

Attached updated code with removed all commented code.main.cpp (13.9 KB)

  1. First I need to open the SDL window With background Color Black.

  2. Based on delay , it will start the image scrolling.

Your comments

  1. If you want scrolling to occur, simply move the camera to the right, at each update.
    Just open the SDL window only not scrolling.

  2. If you want to delay the scrolling, have a timer counting up (or down) and when it reaches a certain value, set a bool to true.
    Check the bool and whenever that bool is true, scroll the camera to the right.
    Where i have to put the timer part in the source.

Please do the needful. Many Thanks

Put the timer (i.e a float variable) and the bool at the top of the source code, where you’ve put the variables WindowWidth, WindowHeight, sectionWidth, numSection etc.
Set the float variable to a value, for example 5.0f and then, in the Update function, decrease the float variable.
After that, check if the variable has reached 0.0f, and if that’s the case, set the bool variable to true, which starts the camera scrolling.

float MyTimer = 5.0f;
bool ScrollingEnabled = false;

if(!ScrollingEnabled)
{
	MyTimer -= DeltaTime;

	if(MyTimer <= 0.0f)
	{
		MyTimer = 0.0f;

		ScrollingEnabled = true;
	}
}

else
	Camera.XPosition += Camera.Velocity * DeltaTime;

HI Naith

Thanks for your response. I will check and get back to you. Once again many thanks.

Hi Naith

your code works perfect. Many Thanks and great Support from you.

How can i retain(without closing) the SDL window for image scrolling 5 rows.
As of now after each row scroll completed SDL window closed, again i am invoking the SDL window for next row.

Attached updated source code (Included your code also) . main.cpp (14.4 KB)

Looking forward your reply. Many Thanks.

There’s a few things I don’t really understand with your code.

Why do you have 2 different update methods, Update and UpdateEvenRow, which are identical? You only need one of them, in my opinion.

Why does your window close when the end of the game world is reached?
Do you want the player and camera to stop at the end of the game world?

Update() - Scrolling from Right to Left
UpdateEvenRow() - Scrolling Left to Right.

Why does your window close when the end of the game world is reached? - Actually its not game application i just changed to Image scrolling. We have 5 row of images.

MY application do follows.

  1. Open SDL Window
  2. Based on timer - 1 row image scroll from right to left using update method.
  3. Retain the SDL window without close Based on timer 2 row image scrolling from left to right using UpdateEvenRow method.
  4. Retain the SDL window - 3 row image scrolling from right to left
    Similar to 5th row image.
  5. Once 5th row scrolling completed SDL window should be closed.

Kindly do the help. Many Thanks

Then I understand.
You don’t really need a player then, just use a camera and control when it should scroll left and right and also when to move down to the next row of images before the next row scrolling occurs etc.

  1. So the first row should scroll to the right, second row to the left, third to the right and so on?

  2. Will the amount of images per row always be the same or will it vary (for example 4 images on the first row, 6 on the second etc)?

  3. Should the camera smoothly change the row or will it be enough that the camera snaps to the next row when a horizontal scroll is completed?

**First row - Scroll - Right to Left **
Second row - Scroll - Left to Right and so on.

Will the amount of images per row always be the same or will it vary (for example 4 images on the first row, 6 on the second etc)?
It will vary row by row.

Should the camera smoothly change the row or will it be enough that the camera snaps to the next row when a horizontal scroll is completed?
– Once First row completed it will wait for next parameters from user for second row image scrolling.

I hope you understand my requirements.

Do the help. Many Thanks.