I've been working on a game with Clojure/Swing lately and the simplest
way to avoid flashing is to draw to a bufferedImage first, then draw
that bufferedImage all at once. This means that parts of the screen
that don't change won't be briefly overwritten by the background
color, avoiding flashing. Here's some code:

(defn render [game window]
  (let [#^BufferedImage image (.createImage window window-width window-
height)
        #^Graphics gfx (.createGraphics image)
        #^Graphics2D gfx2 (.getGraphics #^JFrame window)]

      (render-background gfx)
      ;draw more stuff on gfx here, eg, your draw-boid would go here

      (.drawImage gfx2 image 0 0 window))) ;finally draws the buffered
image to the screen all at once

--
Ryan Sattler

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to