Your approach worked! This is the code that I used to fix the double
buffering:

in init:

bitmap=Bitmap.createBitmap(width,height, Bitmap.Config .ARGB_4444);

in run, c is the canvas here:

if(c!=null)
                                                {c.setBitmap(bitmap);
                                                doDraw(c);}
                                                c = 
mSurfaceHolder.lockCanvas(null);
                                                loopEndTime = 
System.currentTimeMillis();
                                                loopTime = (int) (loopEndTime - 
loopStartTime);
                                                
c.drawBitmap(bitmap,0,0,mLinePaint2);

                                                if (loopTime < loopDelay) {
                                                        if (currentVisual != 
null) {
                                                                try {
                                                                        
Thread.sleep(loopDelay - loopTime);
                                                                } catch 
(InterruptedException e) {
                                                                        
Log.v("theview", "Thread.sleep", e);

                                                                }
                                                        }

                                                }

                                        }
                                } finally {

                                        if (c != null) {
                                                
mSurfaceHolder.unlockCanvasAndPost(c);
                                        }


using this approach:

- create a bitmap
- attach a canvas to it
- do the rendering into that canvas
- lockCanvas
- draw your bitmap into the backbuffer
- unlockAndPost

On Feb 20, 7:44 am, Peter Webb <[email protected]> wrote:
> In fact, the whole idea is to *not* create a new bitmap on each
> frame.  Create the bitmap and clear it at the start of your animation,
> then just keep drawing to this bitmap. You keep it in scope, so the
> stuff you draw to the bitmap in previous frames is remembered. The
> only additional overhead from what you are doing now is writing out
> the bitmap when you have added all the new polygons for that frame.
> This is just a block copy, and appears fast.
>
> My animation loop works exactly this way, and whilst I haven't
> measured how long it takes to write the bitmap, I can assure my
> animation loop is very smooth.
>
> On Feb 20, 4:40 am, Cliff Davies <[email protected]> wrote:
>
> > Painting to a bitmap and copying to the canvas works fine and is ideal for
> > what you're doing. No need to clear your bitmap between frames.
> > On 19 Feb 2011 14:59, "MobileVisuals" <[email protected]> wrote:> I 
> > can't paint the whole screen for every frame, since the animation is
> > > based on new polygons painting over the old ones. This creates a
> > > pattern. If I painted over the old polygons, there would be no
> > > pattern.
>
> > > Peter Webb, you suggested that I should paint everything to a Bitmap.
> > > Wouldn't that be too slow for an animation? I mean I would have to
> > > create a new fullsize Bitmap for every frame.
> > > -------------------------------
> > > Sorry for the old redundant postings in this thread. They got posted
> > > by mistake, since I tried to create a new thread, when it seemed like
> > > the earlier thread was not posted.
>
> > > On Feb 19, 10:49 am, MobileVisuals <[email protected]> wrote:
> > >> Which approach to you think is the best for implementing double
> > >> buffering?
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Android Developers" group.
> > > To post to this group, send email to [email protected]
> > > To unsubscribe from this group, send email to
> > > [email protected]
> > > For more options, visit this group at
> > >http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to