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