开发者

Android: 2D. OpenGl or android.graphics?

开发者 https://www.devze.com 2022-12-28 17:48 出处:网络
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:

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 bi开发者_如何学编程tmaps 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号