Sped up loading on ipad by a lot.
This commit is contained in:
@@ -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