0

Ok, so at this point, I have a project setup with a canvas, surfaceview, and a bar has to move across the screen.

I have setup everything like this:

-Main activity class
     SurfaceView class
         -while(true) {   c.drawRect(x & y)   }  (using X, Y position)
     }
  Thread barMovement {
  while(true){  x+=1; y+=1; }
  }
}

Question:

So this works, but I have noticed that it's not very smooth. Some times, the bar goes a little faster, some times its slower.

I was wondering if this method is the best way to do it? When looking at apps like FlappyBird for example, the movement is absolutely perfect. How do they achieve this?

Thanks, Jason

323go
  • 14,143
  • 6
  • 33
  • 41
  • might want to read up on [Android Animations](http://developer.android.com/training/animation/index.html) – panini Jun 19 '14 at 03:46
  • Compute the position as a function of the time. And don't believe this question is no duplicate. By the way, adding 100 would make it 100 times faster... an improvement??? – maaartinus Jun 19 '14 at 04:48
  • I understand that making it +=100 would make it faster, but I need it to be smooth as well. Making it += 100 would make it hop down the screen. – user3610776 Jun 19 '14 at 05:00
  • I'd rather just switch from SurfaceView to using some actual gaming framework altogether, assuming this is a game. By the way, I'm guessing in your case, the problem is that you are just saying += 1; instead of making it be determined by a velocity and as a function of time, sliced up into pieces: http://stackoverflow.com/questions/23995854/how-to-track-time-in-libgdxandroid/23996041#23996041 – EpicPandaForce Jun 19 '14 at 07:52
  • Erm, i'm not familiar with OpenGL. If possible, could you guide me into the right direction? I'm somewhat new to Android. – user3610776 Jun 19 '14 at 08:53

0 Answers0