Sped up loading on ipad by a lot.

This commit is contained in:
Bryce Covert
2015-09-16 09:11:39 -07:00
parent f4403de5ca
commit 3de4943f67
2 changed files with 30 additions and 12 deletions

View File

@@ -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)))