# Scrolling and Parallax scrolling in 2D game

I'm developing a 2D side-scrolling game.I have a scrollable bitmap for background with size 2400x480.How can i scroll this bitmap?I have searched for algorithms but i can't find any solution.

I know that i can do it with following code:

for(int i=0;i<100;i++)
draw(bitmap,2400*i,480);


So it will scroll bitmap for 240000 pixels.

But i don't want to draw images which stays out of screen(with size 800x480).

How can i render scrolling tile?How can i give velocity to it?(For parallax scrolling after normal scrolling)

## 1 Answer

This is not how you should scroll your bitmap. You should override the draw method and measure the time from the last draw,with this time you will know how much pixels you have to scroll your bitmap. Imagine your CPU is super-fast, with your code, the bitmap will scroll at the speed of light!

• Are there any algorithm for this issue?I searched a lot but i can't find any solution. May 7, 2012 at 10:57
• It's not an issue.your algorythm was bad designed. How could you imagine that the background scroll at the good speed if you don't even use a time-related parameter? May 7, 2012 at 11:42
• The problem isn't that.My draw function is time independent.I'm using deltaTime for animations only.I don't know much about scrolling.If i learn its logic i can create an algorithm. May 8, 2012 at 19:17
• Scrolling is an animation too. May 9, 2012 at 8:24
• Any sample or tutorial for that? May 9, 2012 at 15:32