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