Fork me on GitHub
#quil
<
2021-10-26
>
Joe11:10:57

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?

Joe11:10:22

(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)12:10:45

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

Joe12:10:57

Thank you!

Ju位ian (he/him)12:10:16

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

Joe13:10:00

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

Joe13:10:26

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

Ju位ian (he/him)08:10:26

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

Joe09:10:24

Ah, thank you!