Jaylib - 3, Basics

John Gabriele

2020-12-30

(Previous article: Jaylib - 2, Docs)

I’m learning Jaylib/Raylib myself as I write this, but here are a few morsels I can provide:

Here’s an example of how that all looks:

#!/usr/bin/env janet

(import jaylib :as jl)

(def screen-width  800)
(def screen-height 400)

(defn init-game
  []
  (jl/init-window screen-width
                  screen-height
                  "Title Goes Here")
  (jl/set-target-fps 60)
  (jl/hide-cursor))

(defn update-game
  []
  (comment "Nothing to update at the moment."))

(defn draw-game
  []
  (let [[x y] (jl/get-mouse-position)]
    (jl/draw-circle-gradient x y 40 :lime :red)))

(defn main
  [& args]
  (init-game)
  (while (not (jl/window-should-close))
    (jl/begin-drawing)
    (jl/clear-background [0 0 0])
    (update-game)
    (draw-game)
    (jl/end-drawing))
  (jl/close-window))

(Please excuse the temporary lack of proper Janet syntax-highlighting here.)

Running this will produce a window where the colorful circle follows your mouse around:

Some comments on that code:

(Next up: Jaylib - 4, The Bouncing Square)


Notice any errors, glaring omissions, or just clumsy wording? Please email me at approximately <jgabriele©fastmail·fm>. Thank you!