fading in and out working well.
This commit is contained in:
@@ -16,15 +16,16 @@
|
||||
[com.badlogic.gdx Application Audio Files Game Gdx Graphics Input
|
||||
InputMultiplexer InputProcessor Net Preferences Screen]))
|
||||
|
||||
(defn update-fade [entities current-time]
|
||||
(if (:fade entities)
|
||||
(let [time-shown (- current-time (:start-time entities))
|
||||
entities (assoc-in entities [:fade :opacity] (max (- 1.0 time-shown) 0.0))]
|
||||
(if (= 0.0 (get-in entities [:fade :opacity]))
|
||||
(do (utils/play-sound (:music entities))
|
||||
(dissoc entities :fade))
|
||||
entities))
|
||||
entities))
|
||||
(defn tween [id screen path start end time finish]
|
||||
(let [start-time (or (:total-time screen) 0.0)]
|
||||
(fn [e total-time]
|
||||
(let [delta-time (- total-time start-time)
|
||||
pct-done (min (/ delta-time time) 1.0)
|
||||
e (assoc-in e path (+ start (* pct-done (- end start))))]
|
||||
(if (= 1.0 pct-done)
|
||||
(update-in (finish e) [:tweens] dissoc id)
|
||||
e)
|
||||
))))
|
||||
|
||||
(defscreen title-screen
|
||||
:on-show
|
||||
@@ -40,15 +41,20 @@
|
||||
:scale-y 80
|
||||
:opacity 1.0)
|
||||
:music music
|
||||
:volume 1.0
|
||||
:start-showing? false
|
||||
:start-playing start-playing}))
|
||||
:start-playing start-playing
|
||||
:tweens {:fade-in (tween :fade-in screen [:fade :opacity] 1.0 0.0 1.0 #(do (utils/play-sound (:music %)) %))}
|
||||
}))
|
||||
|
||||
:on-render
|
||||
(fn [screen [entities]]
|
||||
(let [entities (-> entities
|
||||
(update-in [:start-time] #(or % (:total-time screen)))
|
||||
(update-fade (:total-time screen)))]
|
||||
(render! screen [ (:overlay entities) (:start-playing entities) (:fade entities)])
|
||||
(let [entities (reduce (fn [e f]
|
||||
(f e (:total-time screen)))
|
||||
entities
|
||||
(vals (:tweens entities)))]
|
||||
(music! (:music entities) :set-volume (:volume entities))
|
||||
(render! screen [(:overlay entities) (:start-playing entities) (:fade entities)])
|
||||
entities))
|
||||
|
||||
:show-screen (fn [entities]
|
||||
@@ -58,9 +64,15 @@
|
||||
nil)
|
||||
|
||||
:on-touch-up (fn [screen [entities]]
|
||||
(utils/stop-sound (:music entities))
|
||||
(set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen)
|
||||
nil)
|
||||
(-> entities
|
||||
(assoc-in [:tweens :fade-out]
|
||||
(tween :fade-out screen [:fade :opacity] 0.0 1.0 2.0
|
||||
(fn [entities]
|
||||
(utils/stop-sound (:music entities))
|
||||
(set-screen! @(resolve 'advent.core/advent) scene/scene dialogue/talking-screen dialogue/choice-screen inventory/inventory-screen safe/safe-screen)
|
||||
entities)))
|
||||
(assoc-in [:tweens :fade-out-music]
|
||||
(tween :fade-out-music screen [:volume] 1.0 0.0 1.8 identity))))
|
||||
|
||||
:on-resize (fn [screen entities]
|
||||
(size! screen 1280 960)))
|
||||
|
||||
Reference in New Issue
Block a user