[plt-scheme] Flicker-free redrawing of canvas
At Tue, 31 May 2005 05:44:19 -0700 (PDT), Noel Welsh wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hi all,
>
> I'm implementing Pacman using MrEd, so I can try out some
> AI ideas on top of it. It works, but the screen flickers
> horribly. Clearly this yields unacceptable working
> conditions for my AI. I've tried using double buffering --
> drawing to an off screen bitmap% and then dumping that
> bitmap to the canvas's dc<%> using the draw-bitmap method.
> It still flickers. This code is thus:
>
> (define/override (on-paint)
> (let ((dc (send this get-dc)))
> ;; draw everything on the bitmap, then bulk copy
> ;; the bitmap to the current display. Basically
> ;; double-buffering.
> (send bitmap-dc clear)
> (draw-map bitmap-dc)
> (draw-pacman pacman bitmap-dc)
> (send dc draw-bitmap bitmap 0 0 'solid
> background-colour #f)
> ;(send dc clear)
> ;(draw-pacman pacman dc)
> ))
>
> Is there any way I can I avoid this problem?
Probably you also want to avoid creating the bitmap on each call to
on-paint and instead control when new bitmaps are created yourself
(since on-paint is called by system).
Robby