realbasic-games
[Top] [All Lists]

Re: Canvases sometimes black

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Canvases sometimes black
From: Lars Jensen <larsjensen at rcn dot com>
Date: Mon, 27 Jun 2005 12:01:55 -0400
Delivered-to: realbasic-games at lists dot realsoftware dot com
>> AutoBufferingCanvas works by intercepting the Paint event before it gets to
>> your canvas (subclasses can do this, it's what events are for).
> 
> So how would you do animation with such a beast?  It sounds to me
> that this would be great for "normal" purposes, where you want to
> draw some content and then leave it alone (like a business chart or
> whatever).  But maybe not so good for games, where you need to
> frequently draw directly to the canvas's graphics property.

If you need direct drawing for speed, then AutoBufferingCanvas might not be
the best choice. It's meant for the situation "Hmm, I don't like that
flicker -- I'll just insert AutoBufferingCanvas between Canvas and my
subclass and be done with it."

That said, it might be fast enough for some games -- I've used it in
canvases that support click and drag (such as the demo project). 99% of it
is this routine, called by the Paint event:

=================

Sub PaintBuffered(g as Graphics)
  
  dim Destination as Graphics
  
  Destination = g // assume that we won't get a buffer
  
  // Try to get a buffer, except on Mac OS X, which is
  // already double-buffered. Re-use an existing buffer
  // if it's the right size to save time and memory.
  
  #if TargetCarbon // RB 4.5 doesn't do "#if not ..."
  #else
    
    if g <> nil then
      
      if Buffer = nil or g.Width <> Buffer.Width or g.Height <>
Buffer.Height then
        Buffer = NewPicture(g.Width, g.Height, 32) // 32-bit
      end if
      
      if Buffer <> nil then
        Destination = Buffer.Graphics
      end if
      
    end if
    
  #endif
  
  // This fires off our new Paint event, which any
  // instance of this class should implement as if it
  // were a regular Canvas -- it will simply paint to
  // what we have selected as the optimal Graphics object.
  
  Paint Destination
  
  // Now that we have painted, then it's time to transfer
  // our buffer to the actual Graphics object that we were
  // given at the start of all this. Unless we have no
  // buffer, in which case we just finished painting to
  // that very Graphics object, and we're done.
  
  if Buffer <> nil then
    g.DrawPicture Buffer, 0, 0
  end if
  
End Sub

=================

Comments on robustness or flexibility are welcome.

lj
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>