Sprite atlas module loading an image
This commit is contained in:
parent
ca5877d9e5
commit
96bc3717ec
48
src/sprite_atlas.clj
Normal file
48
src/sprite_atlas.clj
Normal file
@ -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"))
|
||||||
|
:-)
|
||||||
Loading…
x
Reference in New Issue
Block a user