Sped up loading on ipad by a lot.
This commit is contained in:
@@ -122,11 +122,16 @@
|
|||||||
(defn map-from-resource [filename]
|
(defn map-from-resource [filename]
|
||||||
(let [pm (pixmap filename)
|
(let [pm (pixmap filename)
|
||||||
black (color 0 0 0 255)
|
black (color 0 0 0 255)
|
||||||
painful (color 255 0 0 255)]
|
painful (color 255 0 0 255)
|
||||||
(vec (take-nth scale (for [x (range (pixmap! pm :get-width))]
|
result (transient [])
|
||||||
(vec (take-nth scale (for [y (reverse (range (pixmap! pm :get-height)))
|
scale (long scale)
|
||||||
:let [current-color (color (pixmap! pm :get-pixel x y))]]
|
height (long (pixmap! pm :get-height))]
|
||||||
(cond
|
(doseq [^long x (range (/ (pixmap! pm :get-width) scale))
|
||||||
(color! current-color :equals black) 0
|
^long y (range (/ height scale))
|
||||||
(color! current-color :equals painful) 2
|
:let [
|
||||||
:else 1)))))))))
|
current-color (color (pixmap! pm :get-pixel (unchecked-multiply scale x) (unchecked-subtract height (unchecked-multiply scale y))))]]
|
||||||
|
(conj! result (cond
|
||||||
|
(color! current-color :equals black) 0
|
||||||
|
(color! current-color :equals painful) 2
|
||||||
|
:else 1)))
|
||||||
|
(partition (/ (pixmap! pm :get-height) scale) (persistent! result) )))
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
[play-clj.utils :refer :all]
|
[play-clj.utils :refer :all]
|
||||||
[play-clj.math :refer :all]
|
[play-clj.math :refer :all]
|
||||||
[play-clj.g2d :refer :all]
|
[play-clj.g2d :refer :all]
|
||||||
|
[play-clj.entities :refer [->TextureEntity]]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.edn :as edn]
|
[clojure.edn :as edn]
|
||||||
[clojure.string :as str])
|
[clojure.string :as str])
|
||||||
@@ -152,10 +153,22 @@
|
|||||||
(texture! frame :flip true false)
|
(texture! frame :flip true false)
|
||||||
frame))))
|
frame))))
|
||||||
|
|
||||||
(defn split-texture [file [w h] frames]
|
(defn split-texture [file [tile-width tile-height] frames]
|
||||||
(let [sheet (texture! (get-texture file) :split w h)]
|
(let [sheet (get-texture file)
|
||||||
(for [i frames]
|
sheet-obj ^TextureRegion (:object sheet)
|
||||||
(aget sheet 0 i))))
|
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
|
||||||
|
(unchecked-add x (unchecked-multiply tile-width frame))
|
||||||
|
y
|
||||||
|
tile-width
|
||||||
|
tile-height)
|
||||||
|
(->TextureEntity new-tex))))
|
||||||
|
)
|
||||||
|
|
||||||
(defn make-anim [file [w h] speed frames]
|
(defn make-anim [file [w h] speed frames]
|
||||||
(animation speed (split-texture file [w h] frames)))
|
(animation speed (split-texture file [w h] frames)))
|
||||||
|
|||||||
Reference in New Issue
Block a user