2D side scrolling platformer: Facing problems with background/flat floor surface.

Hey guys,

I am working on a 2D side scroller game. Where a ball is moving continuously towards right . I used a camera to follow the ball as soon as ball reaches the center of screen. I created a horizontal line to look like the surface on which the ball is rolling.

line runs from x=0 to x=800 (i.e screen width)

NOTE: (0,0) coordinate is at top left corner of display.

Problem: My display is 800 x 400 . Camera follows the ball, but soon the ball crosses x=800 and starts moving in black background. I want that line surface to stay there instead of going out of bound.

Actually, its not just about the line segment anymore. The value of x=800 is very crucial because i draw random obstacles (the enemy TRIANGLES) from that point. So if the ball passes that 800th pixel , generated obstacles from x=800 also move off the screen along with my line. So the ball wont be facing any obstacles (where is the fun in that?). We dont want that to happen.

I did a little digging on internet, but nothing wraps around my head.

What should be done here? This is just my first c++ game project using ALLEGRO 5.0.10, so i might be skipping things that can solve the issue.

Need expert inputs to tackle this problem.

Hope these screenshots manage to show, what the real problem is:

[img]http://s22.postimg.org/erpdq7n3x/image.jpg[/img][/url]
[img]http://s22.postimg.org/mbigs9gal/image.jpg[/img][/url]
[img]http://s29.postimg.org/to2z1wh83/image.jpg[/img][/url]
So what exactly do you want? Do you want to the camera to stop following the ball when it hits the end of the "stage"? Do you want the "surface" picture to horizontally loop so you can move right forever?
I want to move right forever, and that surface is a line segment with a grey rectangle below it. I want it to loop as i move towards right direction.
In this simple case, you could simply draw the surface in the same relative position to the camera always; the viewer wouldn't notice the difference.

In a case where you have a slightly more interesting surface that you would actually want to look like it was moving relative to the ball, you could make note of where the camera's center is and calculate the left and right edges of the screen, then determine where you need to draw the ground. (e.g., if the right edge passes past a multiple of 800 you need to draw another copy of the surface to the right, and once the left edge passes a multiple of 800, you no longer need to draw the surface that has dropped off the screen.)
Topic archived. No new replies allowed.