0
\$\begingroup\$

I am trying to find the best solution for drawing a scrolling background in my app in Java. For now, I have two images and I move them by 1x and put it's thread to sleep for hmm, 5ms.

The problem is here that the background is too fast. What should I do? Probably put the thread to a longer sleep. But when I do this, the background 'freezes' - jumps for 15 pixels each step and it doesn't look smooth.

The main question is: How to handle a thing like this? Should it be done by sleeping it's thread, or maybe I should make positions floats, increment them by 0.1 and move only when they are integers? << this is my idea, I don't have an idea if it would work.

We have floats: width = 1000.0 height = 1000.0; When increment width by 0.1 in each 'update iteration' in a gameloop. If it's a int (1001, 1002, 1003), we move the background. What do you thing? What would be the best way?

\$\endgroup\$
3
  • \$\begingroup\$ Have you tried using delta time yet? \$\endgroup\$ – Sturlen Nov 24 '15 at 12:13
  • \$\begingroup\$ Hmm, I heard about it, but unfortunatelly no :( \$\endgroup\$ – user73483 Nov 24 '15 at 12:21
  • \$\begingroup\$ I'd recommend looking at this article then; it talks about different game loops and how you implement them. \$\endgroup\$ – Sturlen Nov 24 '15 at 12:49

Your Answer

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