0
\$\begingroup\$

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)

\$\endgroup\$
3
\$\begingroup\$

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!

\$\endgroup\$
5
  • \$\begingroup\$ Are there any algorithm for this issue?I searched a lot but i can't find any solution. \$\endgroup\$ – droidmachine May 7 '12 at 10:57
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – VinceFR May 7 '12 at 11:42
  • \$\begingroup\$ 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. \$\endgroup\$ – droidmachine May 8 '12 at 19:17
  • 2
    \$\begingroup\$ Scrolling is an animation too. \$\endgroup\$ – VinceFR May 9 '12 at 8:24
  • 1
    \$\begingroup\$ Any sample or tutorial for that? \$\endgroup\$ – droidmachine May 9 '12 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.