smaller textures.

This commit is contained in:
Bryce Covert
2017-05-26 12:48:07 -07:00
parent d8a145bb67
commit 3ee134f062
34 changed files with 174 additions and 90 deletions

View File

@@ -160,11 +160,14 @@
(defn atlas->texture
([atlas path]
(let [region-name (str/replace path #".png" "")]
(texture (texture-atlas! atlas :find-region region-name))))
(if-let [region (texture-atlas! atlas :find-region region-name)]
(texture region)
(log/error path "not found"))))
([atlas path index]
(let [region-name (str/replace path #".png" "")]
(texture (texture-atlas! atlas :find-region region-name index)))))
(if-let [region (texture-atlas! atlas :find-region region-name index)]
(texture region)
(log/error path index "not found")))))
(defn get-texture
([path]
@@ -349,28 +352,46 @@
(texture! frame :flip true false)
frame))))
(defn split-texture [file [^int tile-width ^int tile-height] frames]
(let [sheet (get-texture file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
^int (unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex)))))
(defn split-texture
([file [^int tile-width ^int tile-height] frames]
(let [sheet (get-texture file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
^int (unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex)))))
(defn make-anim [file [w h] speed frames]
(animation speed (split-texture file [w h] frames)))
([atlas file [^int tile-width ^int tile-height] frames]
(let [sheet (atlas->texture atlas file)
sheet-obj ^TextureRegion (:object sheet)
width ^int (int (.getRegionWidth sheet-obj))
x ^int (int (.getRegionX sheet-obj))
y ^int (int (.getRegionY sheet-obj))]
(for [frame frames
:let [new-tex ^TextureRegion (TextureRegion. sheet-obj)]]
(do
(.setRegion new-tex
^int (unchecked-add x (unchecked-multiply tile-width frame))
y
tile-width
tile-height)
(->TextureEntity new-tex))))))
(defn make-anim-seq [file [w h] speed frames]
(animation speed (map #(get-texture (str file "-" (inc %) ".png")) frames)))
(defn make-anim
([file [w h] speed frames]
(animation speed (split-texture file [w h] frames)))
([atlas file [w h] speed frames]
(animation speed (split-texture atlas file [w h] frames))))
=
(defn make-bird [screen p]
(let [bird-sheet (texture! (get-texture "outside-castle/bird.png") :split 1 2)
bird-stand (animation 0.15 (for [i [0 1]]
@@ -755,3 +776,9 @@
(doseq [resource (:resources screen)]
(asset-manager! *asset-manager* :unload resource))
(app! :log "info"(str "Released resources " (.getDiagnostics *asset-manager*))))
(defn make-anim-seq
([file [w h] speed frames]
(animation speed (map #(get-texture (str file "-" (inc %) ".png")) frames)))
([atlas file [w h] speed frames]
(animation speed (map #(atlas->texture atlas file %) frames))))