quil

Joe 2021-10-26T11:03:57.003100Z

In my program right now I do (frame-rate 30) in my setup function and then everything renders at 30fps. However, I have a static background which doesn't need to re-render after the first time. It is possible to either do a 'draw once', or set the frame-rate on the background to a much lower rate, like 1?

Joe 2021-10-26T11:04:22.003200Z

(I think I might have asked this before on this channel a while ago but I didn't note down the response 😞 )

Juλian (he/him) 2021-10-26T12:37:45.003400Z

you can render your background in your setup function once, then it won't be re-rendered in the draw function

Juλian (he/him) 2021-10-26T12:42:43.003600Z

simple example here: http://quil.info/sketches/show/856cf5fa9b9ed5ac07bfc543d333c467a4a7c26337c3e1cc5b313f0e9279030e

Joe 2021-10-26T12:42:57.004100Z

Thank you!

Juλian (he/him) 2021-10-26T12:48:16.004300Z

you can make nice things with keeping the background, like a fading trail of a moving object: http://quil.info/sketches/show/10c044351a714e7dcba00e4e91a48e0e5ed655c591d1b0038547f2a1dfca5dd0

Joe 2021-10-26T13:36:00.004500Z

Hm, this isn't working like I expected. I draw the background in setup, it stays for one frame, and then disappears on the second frame! This is the setup function

(defn setup []
  (q/frame-rate 1)
  (let [ss (-> game-state
               (assoc :cursor [(int (/ horiz-tiles 2)) (int (/ vert-tiles 2))]
                      :images (load-sprites))
               add-sprites-to-units)]
    (draw-terrain (vals (:field ss)) (:images ss))
    ss))
And https://github.com/RedPenguin101/pocket-gettysburg/blob/main/src/general_slim/ui.clj#L122 is the full file

Joe 2021-10-26T13:37:26.004900Z

I'm assuming the problem is that I'm not using background to draw my background

Joe 2021-10-29T09:19:24.006300Z

Ah, thank you!

Juλian (he/him) 2021-10-28T08:23:26.006100Z

the problem is you are overwriting the background in draw-state by calling q/background (line 227)