zooming and panning!

This commit is contained in:
Bryce Covert
2016-12-01 09:10:13 -08:00
parent 9d12bc549c
commit 3370756f1c
3 changed files with 92 additions and 32 deletions

View File

@@ -124,15 +124,12 @@
~@forms
(change-script-state ~entities false))))))))
(defn bound-to-camera [x length zoom]
(min (- length (* length 0.5 zoom ))
(max (* length 0.5 zoom )
x)))
(defn pan-to [screen entities x y scale-fn & [ease duration]]
(let [ease (or ease tween/ease-in-out-quadratic)
duration (or duration 3.0)
target-zoom (min 0.95 (max 0.75 (scale-fn [(max 0 (min 319 x)) (max 0 (min 240 y))])))
target-zoom (min utils/min-zoom (max utils/max-zoom (scale-fn [(max 0 (min 319 x)) (max 0 (min 240 y))])))
current-zoom (get-in entities [:cam :zoom] 1.0)
;; don't zoom if it's a subtle difference
@@ -140,13 +137,15 @@
0.07)
current-zoom
target-zoom)
target-x (bound-to-camera x 320 target-zoom)
target-y (bound-to-camera y 240 target-zoom)]
target-x (utils/bound-to-camera x 320 target-zoom)
target-y (utils/bound-to-camera y 240 target-zoom)]
(if (and (or (not= target-x (get-in entities [:cam :x]))
(not= target-y (get-in entities [:cam :y]))
(not= target-zoom (get-in entities [:cam :zoom])))
(not (get-in entities [:cam :paused?])))
(-> entities
(assoc-in [:cam :ideal-x] x)
(assoc-in [:cam :ideal-y] y)
(assoc-in [:tweens :cam-zoom]
(tween/tween :cam-zoom screen
[:cam :zoom]
@@ -715,7 +714,7 @@
(update-in [:tweens] dissoc :cam-zoom :cam-x :cam-y)
(assoc-in [:cam :x] 160)
(assoc-in [:cam :y] 120)
(assoc-in [:cam :zoom] 0.95))
(assoc-in [:cam :zoom] utils/max-zoom))
e)
(if music-changed?