0

I'm a newbie in android programming, my purpose is to draw multiple identical drawables (and animate them changing their x y coordinates) in a canvas returned calling something like mySurfaceHolder.lockCanvas(). The number of drawables is dynamic and changes with time.

How is it possible keeping the high as possible frame rate?

(Sorry for bad english)

Murray
  • 97
  • 8

1 Answers1

0

As far as I know, there are two common ways to draw animated images yourself on the screen: SurfaceView OR GLSurfaceView (Android official site).

For the better performance of drawing multiple identical images, my suggestion is to draw images on GLSurfaceView instead of SurfaceView.

If the amount of identical images to draw is large, then the frame rate to draw onto SurfaceView will be affected by the device's computing power (depends on CPU speed). On the other hand, using GLSurfaceView mostly depends on GPU speed, so I suggested using GLSurfaceView to draw images.

But if you are not familiar with OpenGL ES. The most efficient way of drawing multiple identical images is to separate your logic statements from images by drawing code segments with another thread. Drawing using drawable.draw(canvas) or canvas.drawBitmap() will be fine.

ps. Using GLSurfaceView will require translating the Drawables to the texture before they can be drawn on GLSurfaceView.

IEBasara
  • 501
  • 3
  • 14
  • The frame rate is not affected by the speed of the device when drawing to GLSurfaceView? Not sure what you're trying to say here. The frame rate obviously depends on the speed of the device, no matter how you render. – Reto Koradi May 07 '14 at 16:51
  • GLSurfaceView is just a wrapper around SurfaceView. You can use GLES to render on a SurfaceView. The distinction is between rendering with Canvas and rendering with GLES. (See also http://source.android.com/devices/graphics/architecture.html .) – fadden May 08 '14 at 00:17
  • Hi, @Reto. It's been a while that I did not review the responses of my answer. I agree with your point that no matter how we render, the frame rate obviously depends on the speed of the device. But what I meant was it depends on how many sprites we're gonna use. – IEBasara Aug 01 '17 at 03:14
  • I'm sure at that time, I solved the low frame rate issue by using GLSurfaceView instead of SurfaceView in some devices which run Android 4.2. (But I'm not sure if we still can tell the frame rate difference between SurfaceView or GLSurfaceView in current devices.) Some performance information between SurfaceView and GLSurfaceView is here: https://stackoverflow.com/questions/5169338/android-deciding-between-surfaceview-and-opengl-glsurfaceview – IEBasara Aug 01 '17 at 03:25