0

I have a tile background with 2400x480 pixels.Also one more far layer for parallax effect.Is that drawing background with a for loop logical?

for(int i=0;i<100;i++) {
    //Drawing code like 0+2400*i ...
}
MByD
  • 135,866
  • 28
  • 264
  • 277
droidmachine
  • 577
  • 2
  • 8
  • 24
  • Err, so you have one background that is tiled? Or is the background one quad and the tiles overlay it? One tile is 2400x480? – Stefan Hanke Apr 12 '12 at 04:54
  • @StefanHanke yes i have only one large tile(2400x480) and my character moves on it.I want to scroll this tile.Also i have an far layer for parallax.How can i draw my background? – droidmachine Apr 12 '12 at 19:26
  • Thanks for reminding. I still do not _really_ grasp what you want. For a background, use a textured screen-aligned quad. If you need to scroll it, please have a look [here](http://stackoverflow.com/a/10013128/1262542). For a 2D tile game, I would expect two nested for-loops (for x and y). Do you intend to just repeat the tile background? – Stefan Hanke Apr 15 '12 at 18:00
  • @StefanHanke I have background with two layers.Far layer is for parallax effect.And i want to scroll(repeat) my background with these two tillable background.How can i do it effectively? I also have a camera class with x and y. – droidmachine Apr 15 '12 at 20:37
  • I comprehend the following: The far layer is a tile, and you want it scrolled slowly with the texture repeated, then there's another layer scrolled a bit faster, with another texture that is to be repeated too? The scrolling is in one direction? – Stefan Hanke Apr 16 '12 at 04:46
  • @StefanHanke Yes you are right.So how can i do it? – droidmachine Apr 16 '12 at 10:34

1 Answers1

3

I hope this gets you started, but I really don't know...

I assume in the following that the texture is displayed all at once. Due to the size of the texture -- 2400*480 = (3*800)*480 -- I think this may not be correct, but anyway.

For each layer, you have two quads with fixed texture coordinates. Initially, one the first quad is visible; in the course of the animation, the first is moved out of the screen and the second in. The texture border must match, otherwise a crack will be visible.

+-------------++-------------+
|             ||             |
|             ||             |
+-------------++-------------+
^             ^
   visible

... as time progresses ...
+-------------++-------------+
|             ||             |
|             ||             |
+-------------++-------------+
      ^             ^
         visible

You can do this for the bottom layer and the next layer. Use different velocities for layers of different distance. You will need blending when there is more than one layer.

If the first assumption proves to be incorrect, you need to modify texture coordinates during the animation. There is one full-screen quad, and the texture coordinates are setup for one third of the texture. Then, linearly translate all four coordinates in the same direction until the top is hit. At this point you somehow need to begin to show the first third again -- using a second quad for example.

Stefan Hanke
  • 3,458
  • 2
  • 30
  • 34