Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Scrolling background

Author
Message
Plastrix
16
Years of Service
User Offline
Joined: 23rd Feb 2008
Location:
Posted: 23rd Feb 2008 23:56 Edited at: 24th Feb 2008 01:08
What is the best way to create a scrolling terrain?

Is it using sprites or will this slow it down too much any help would be great thanks
Dark Dragon
16
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 25th Feb 2008 17:10
Try this....
(Forgive me. my code is always hard to understand...)
Plastrix
16
Years of Service
User Offline
Joined: 23rd Feb 2008
Location:
Posted: 26th Feb 2008 00:16
Thanks alot i will ty it out
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 26th Feb 2008 03:38
The "best" way to scroll a background depends upon who you ask.

Another way you could do it would be to do the following:
1. Draw images of equal sizes (32 X 32, 64 X 64, etc.)
2. Create an array that is based upon the game screen size and which holds the values of the images to display.
3. Code a subroutine/function that will look at a part of the array that you are scrolling through and paste a screen's worth of images to a separate bitmap. You would use an offset of some sort to provide for smooth scrolling (i.e., your images are 32 pixels wide, you scroll at 2, 4 or 8 pixels to give the effect of speed).
4. Grab the bitmap and paste it to screen 0.

You could draw all of the images to bitmaps and then scroll through the bitmaps and it would be faster, but the above method works okay for me. You could use the same code to write a top-down game too.

It seems like there was at least one good 2D scrolling snippet available in the codebase. You should check there.

LB
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 2nd Mar 2008 21:59 Edited at: 2nd Mar 2008 22:04
Haha, I wrote a whole huge post and then accidently refreshed the screen...anyway, in Los Mineros I have a function like this:



You'll notice that this is for Box2D, but you get the idea. I just call this function whenever the player gets too far from the center of the screen and everything moves onward.

One advantage of doing this is that the character does not have to be "locked" to the screen. If you call the function something like this, you can allow the character a small range of motion without the screen moving, and the screen will glide after the player rather than snapping to them:



Login to post a reply

Server time is: 2024-05-06 20:57:46
Your offset time is: 2024-05-06 20:57:46