Jump to content

How to scroll a background smoothly


dlobalzo
 Share

Recommended Posts

Hi everyone!

I'm trying to make a top down racing game, but I can't find a way to make a proper scrolling background. Every example I find is about tiles but my background is not something I can repeat horizontally. The background image is basically the track, so I need that image to be 100% width and repeated vertically, with an infinite vertical scroll.

Can you please give me a hint?

Thanks in advance!
Damian

Link to comment
Share on other sites

Hello, I'm not sure if I get what your problem is, but.

If you have an image of background where let's say your road is something like this:

h road h

h road h

h road h

h road h

If you need to scroll this infinitely then you can just add one more image above this one and do that repeatedly whenever needed.

h road h

h road h

h road h

h road h

-----------------------  end of the viewport

h road h

h road h

h road h

h road h

----------------------- start of the viewport

Check when the bottom image's top is lower than vieport's top and then just display the other image above. When the bottom image gets out of bounds you just change it's y coordinate and place it above the one in the viewport, this way you utilize jsut two background images.

Bakcground can be moved as mentioned by tweening or just giving it a velocity and tying it with physics engine.

PS tiles are not the standard, they are not really necessarry every time. They are handy but use them only when you need it if you are not making a tile based game then you probably don't need most of the tile features ;-).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...