From 96bc3717ecf020036646fa2e7018680d632e0e59 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sun, 16 Aug 2026 19:40:44 +0700 Subject: [PATCH] Sprite atlas module loading an image --- src/sprite_atlas.clj | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/sprite_atlas.clj diff --git a/src/sprite_atlas.clj b/src/sprite_atlas.clj new file mode 100644 index 0000000..90bac9a --- /dev/null +++ b/src/sprite_atlas.clj @@ -0,0 +1,48 @@ +(ns sprite-atlas + (:require + [clojure.java.io :as io] + [engine] + [rl :as rl])) + +(defonce state (atom {})) + +(defn init-sprite-atlas [config] + (let [path (:sprite-path @state)] + (if (.exists (io/file path)) + {:atlas (rl/load-texture path)} + (println "Unable to load " path)))) + +(defn handle-sprite-atlas-input [config game] + game) + +(defn update-sprite-atlas [config game] + game) + +(defn draw-sprite-atlas [config game] + (rl/clear-background!* rl/black) + (when-let [atlas (:atlas game)] + (rl/draw-texture!* (:seg atlas) 0 0 rl/white) + (rl/draw-fps 10 10))) + +(defn watch-sprite-atlas [config game] + {}) + +(defn unload-sprite-atlas [game] + (rl/unload-texture! (:atlas game))) + +(defn -main [& sprite-path] + (swap! state assoc :sprite-path (first sprite-path)) + (engine/run-game! + {:title "Sprite Atlas" + :width 1280 + :height 900 + :init #'init-sprite-atlas + :input #'handle-sprite-atlas-input + :update #'update-sprite-atlas + :draw #'draw-sprite-atlas + :unload #'unload-sprite-atlas + :watch-fn #'watch-sprite-atlas})) + +(comment + (future (-main "./source-assets/thai_village.png")) + :-)