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?