开发者

Strange artifacts when rendering lots of bitmaps

I'm writing a simple 2D game engine and rendering various objects to a locked SurfaceVew by calling Canvas.drawBitmap (all the same source bitmap but generally not with 1:1 source to destination scaling).

Everything appears to work as expected until there are a lot of calls per frame to drawBitmap. When this happens I occasionally see a stall (100mS or so) accompanied by an effect that looks as if several frames of rendering have occurred together, i.e. some objects will be drawn twice at two screen locations or a pair of objects moving at the same speed will appear to momentarily get closer together or further apart.

The application is structured as follows (simplified for the sake of example);

initialiseGameObjects();

while(quit==false)
{
 processGameLogic(); // update object positions
 Canvas c = surface_holder.lockCanvas();
 if (c != null) {
  drawGameObjects(c); // draw all objects
  surface_holder.unlockCanvasAndPost(c);
 }
}

As I understand it, the Canvas is a holder for draw requests which get executed when the Post is issued. Presumably there is a limit to the number of requests it can hold and I'm wondering if I'm exceeding this limit (I'm drawing up to a hundred small bitmaps depending on what's on screen at any one time) and inadvertently provoking some kind of flush and upsetting the double buffering in some way, although I've not managed to find any documentation to confirm or disprove this.

开发者_运维问答

Does anyone have any idea what might be going on?

Regards, Steve


You need to sychronize calls to canvas drawing. Check this example of a game driving thread: OnDraw() is not fired, nothing is drawn in surfaceView - Android

EDIT: However I think it may be related to this problem: Android SurfaceView/Canvas flickering after trying to clear it

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜