I just started with game development in android, and I\'m working on a super simple game.
The game is basically like flappy bird.
I managed to get everyt
First of all, Canvas can perform poorly so don't expect too much. You might want to try the lunarlander example from the SDK and see what performance you get on your hardware.
Try lowering you max fps down to something like 30, the goal is to be smooth not fast.
private final static int MAX_FPS = 30; // desired fps
Also get rid of the sleep calls, rendering to the canvas will probably sleep enough. Try something more like:
synchronized (mSurfaceHolder) {
beginTime = System.currentTimeMillis();
framesSkipped = 0;
timeDiff = System.currentTimeMillis() - beginTime;
sleepTime = (int) (FRAME_PERIOD - timeDiff);
if(sleepTime <= 0) {
this.mMainGameBoard.update();
this.mMainGameBoard.render(mCanvas);
}
}
If you want to you can do your this.mMainGameBoard.update() more often than your render.
Edit: Also since you say things get slow when the obstacles appear. Try drawing them to an offscreen Canvas / Bitmap. I've heard that some of the drawSHAPE methods are CPU optimized and you'll get better performance drawing them to an offline canvas/bitmap because those are not hardware/gpu accelerated.
Edit2: What does Canvas.isHardwareAccelerated() return for you?