From 2c2507febf74b29246eb9e1c10d36773eadc4527 Mon Sep 17 00:00:00 2001 From: Remington Covert Date: Mon, 2 Mar 2015 07:11:57 -0800 Subject: [PATCH] parallax scrolling looks awesome. --- desktop/src-common/advent/screens/scene.clj | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index cb3d2b5b..f09e8875 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -443,6 +443,7 @@ parallax-view (Matrix4.) parallax-combined (Matrix4.)] (.update camera) + (.set tmp (.position camera)) (set! (.x tmp) (* (.x tmp) 1.5)) (set! (.y tmp) (* (.y tmp) 1.5)) @@ -453,11 +454,15 @@ (.set parallax-combined (.projection camera)) (Matrix4/mul (.val parallax-combined) (.val parallax-view)) + (let [^Batch batch (.getBatch renderer)] (.begin batch) (.setProjectionMatrix batch parallax-combined) - (entities/draw! (:tex foreground) screen batch) + + (doseq [e (:texes foreground)] + (entities/draw! (assoc e :x (+ (/ (:x e) (.zoom camera)) (- 240 (/ 160 (.zoom camera)) )) + :y (+ (/ (:y e) (.zoom camera)) (- 180 (/ 120 (.zoom camera))))) screen batch)) (.end batch)))) @@ -527,7 +532,8 @@ :override nil :last-pos [0 0]} :foreground {:object nil - :tex (assoc (texture "outsidehouse/fg1.png") :x 75 :y 57 :baseline 1000)} + :texes [(assoc (texture "outsidehouse/fg1.png") :x 0 :y 0 :baseline 1000) + (assoc (texture "outsidehouse/fg2.png") :x (- 320 59) :y 0 :baseline 1000)]} :all-items (assoc items/items :object nil) :started? {:value false