dlobalzo

How to scroll a background smoothly

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

Share this post


Link to post
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 ;-).

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.