29

I'm working with my friend on our first Android game. Basic idea is that every frame of the game the whole surface is redrawn (1 large bitmap) in 2 steps:

  1. Background with some static image (PNG) wipes out previous frame
  2. Then it is sprinkled all over with large number of particles which produces effect of soapy bubbles where there's a pool of about 20 bitmaps which randomly gets picked to produce illusion that all bubbles (between 200 - 300) are all different. Bubbles positions updated on each frame (~50ms) producing effect of moving bubbles.

The math engine is in C (JNI) and currently all drawing is done using android.graphics package very similar (since that was the example I was using) to Lunar Lander. It works but animation is somewhat jerky and I can feel by temperature of my phone that it is very busy. Will we benefit from switching to OpenGL? And as a bonus question: what would be a good way to optimize the drawing mechanism (Lunar Lander like) we have now?

Bostone
  • 36,858
  • 39
  • 167
  • 227

2 Answers2

6

Now I've started to work with OpenGL ES, I would also use it for 2D graphics. This way is the most flexible and it's extremely fast (look at this example code. It's about 2D rendering, and there you can see the power of OpenGL.

It's not the easiest thing to start with, but there are some good tutorials out there - for example, this is a very good one.

Simon
  • 13,173
  • 14
  • 66
  • 90
  • It looks like jayway's tutorial is focused on 3D drawing, unless I'm mistaken. – o0'. May 07 '10 at 23:21
  • the basic initalization stuff is the same for 2d and 3d and if you want to use opengl you have to understand it first;) there are some GL11 (a special OpenGL ES interface which is not available on all devices) methods where you dont have to setup a point of view and stuff like that but most of stuff is important for 2d as well as for 3d – Simon May 11 '10 at 20:55
  • 1
    Hi, I'm developing Android 2D game, and I'm using Canvas to draw graphics. But it's slow, and I thought, using OpenGL will be faster. So I tried the test aplication you suggested, but the result is different than yours. The canvas method is always faster than, OpenGL method. It's wierd. You said, that OpenGL is fast. Do you know, where the problem could be? Here are results of my testing at LG Optimus One with 500 sprites and enabled animation: Canvas: 58ms (17.2413 fps) OpenGL ES: Basic Vert Quads: 104ms (9.615 fps) Draw Texture Extension: 73ms (14.02 fps) VBO Extension: 74ms (13.51 fps) – branoholy Mar 09 '11 at 15:22
  • its possible that they redesigned the canvas drawing methods, this test is not the newest anymore;) but you should also consider that on older phones with android 1.6 eg opengl will be much faster. there are some realy good frameworks for 2d games out there, for example libgdx. maybe take a look at them, in the end moving sprites is not the only thing you will have to do;) – Simon Mar 13 '11 at 08:51
3

Don't redraw the entire screen each time. That's what causes your low framerate. Use the invalidate method to mark the areas that have changed each frame.