Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » 2D game with classes: Background issue

Credits go to Edgar Reynaldo and Neil Roy for helping out!
This thread is locked; no one can reply to it. rss feed Print
2D game with classes: Background issue
CodeOne
Member #15,442
December 2013

ALLEGRO 5.0.10 with c++

I have a 800x400 display

In which I have drawn a horizontal line

#SelectExpand
1void Ground::Render() 2{ 3 al_draw_line(x,y,800+x,y,al_map_rgb(0,255,0),10); //x=0 , y=330 4 5}

A ball is continuously moving on this line . I used transformation to keep the ball at the centre of screen.

After a while ball moves into black screen space as the line was drawn only till x=800 . Line doesnt exist beyond x=800 position.

Is there a way so that I can loop this line to appear continuously ,like forever? As long as ball is moving.

Neil Roy
Member #2,229
April 2002
avatar

If you want a solid line, like a ground surface that never changes on screen, just update your various game object movements, then draw the fixed ground last so it is always on screen, ie: don't move the ground. Though you may wish to make something more dynamic, like a tiled ground and you check an array which states which tile is to be drawn next and you draw it etc.. not sure what you are doing here, you're very vague.

---
“I love you too.” - last words of Wanda Roy

CodeOne
Member #15,442
December 2013

Ok, I was just wondering if I can make it happen. Solved it.

But then i came across this cool software called MAPPY. I used a tile this time instead of a solid line.

tile size : 64x60
I placed 100 such tiles horizontally to look like a ground. So now i have a 6400 pixel wide ground. I used bounce check too.

But again my ball travels pretty fast. Game crashes. I think it may be that because ball crosses 6400th pixel. How to loop this thing ?? gimme an idea to implement such that it never ends.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Yeah, use a map image with twice the size that you want your wrapped background to be, then draw it twice next to each other and then each frame draw out of that buffer to the screen using modulus to find out the coordinates of the background that you should be using.

Or you can draw twice, depending on clipping to get rid of the extra on the sides.

Go to: