scrolling background

Started by
3 comments, last by TinyGameDev 18 years, 11 months ago
the title is probably wrong for this qeustion but i couldn't come up with something better... anyway, i was thinking of having a scrolling background, duh, and i want to have my spaceship in the middle of the screen att all times. now...i have big picture which serves as the background. no, my question is, how can I make the illusion of an unending universe? in other words, how can i make the ship beam through the picture so when it goes out one end, it appears at the other end? the hard part i guess is that i perhaps ahve to draw the background twice, so the user doesn't see the actual border of the picture...or?? thanx a lot for any help

Making Terralysia, wishlist now on Steam <3!

Advertisement
One repeating texture.
One quad that fit the screen.

Scroll the texture with a texture matrix. In other words, offset the s,t values on the background texture when the space ship moves. If the ship moves "right" then add a proportionate amount to the s values of all 4 vertices.

You should reset the s,t values when the texture has scrolled more than once across the screen. This will prevent them from getting too big (or small), which can cause precision issues.

Of course you need to draw the texture using REPEAT in both directions for this to work.

What I did, was, to split a big picture (like 1024 x 1024) into smaller parts, let's say 256 x 256. See them as really big tiles. Make sure you make the entire background 'tiles' bigger than your screen, you can achieve a fast, slick smooth scroll in that way. Make sure you disable alpha blending on a large background, when it's not needed, this increases performance.
Cool, thanx a lot guys.
I'll try your techniques and see which one I mange to implement correctly :P

Thanx

Making Terralysia, wishlist now on Steam <3!

Quote:Original post by greldik
One repeating texture.
One quad that fit the screen.

Scroll the texture with a texture matrix. In other words, offset the s,t values on the background texture when the space ship moves. If the ship moves "right" then add a proportionate amount to the s values of all 4 vertices.

You should reset the s,t values when the texture has scrolled more than once across the screen. This will prevent them from getting too big (or small), which can cause precision issues.

Of course you need to draw the texture using REPEAT in both directions for this to work.




I implemented this technique and it really worked well..but i have a problem. Since it's a multiplayer game, i have a hard time converting the world-coordinates of the other player to screen coordinates. I compare player 1's coordinates with player 2 but it still doesn't work when i render player 2's ship because i change the s/t coordinates of the background texture all the time. that means the when i actually convert the world coordinates to screen coordinats, they are not accurate because of the background. i think...that's the other problem. i'm not really sure.

Making Terralysia, wishlist now on Steam <3!

This topic is closed to new replies.

Advertisement