Fix desync between fade out/in and level loading when game is lagging.
This commit is contained in:
parent
78ce020fcb
commit
eeb95785c7
4 changed files with 33 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
(define-module (game effects)
|
||||
#:use-module (dom canvas)
|
||||
#:use-module (game scripts)
|
||||
#:use-module (game time)
|
||||
#:use-module (ice-9 match)
|
||||
#:use-module (math)
|
||||
|
@ -57,11 +58,21 @@
|
|||
(define game-width 320.0)
|
||||
(define game-height 240.0)
|
||||
|
||||
(define (make-fade-out+in-effect duration)
|
||||
;; on-transition is a last-minute hack to make it possible to sync the
|
||||
;; loading of the next level with the moment when the screen is
|
||||
;; completely black.
|
||||
(define (make-fade-out+in-effect duration on-transition)
|
||||
(define transitioned? #f)
|
||||
(define (maybe-transition)
|
||||
(unless transitioned?
|
||||
(set! transitioned? #t)
|
||||
(on-transition)))
|
||||
(define (draw context t)
|
||||
(if (< t 0.5)
|
||||
(set-global-alpha! context (* t 2.0))
|
||||
(set-global-alpha! context (- 1.0 (* (- t 0.5) 2.0))))
|
||||
(begin
|
||||
(maybe-transition)
|
||||
(set-global-alpha! context (- 1.0 (* (- t 0.5) 2.0)))))
|
||||
(set-fill-color! context "#000000")
|
||||
(fill-rect context 0.0 0.0 game-width game-height)
|
||||
(set-global-alpha! context 1.0))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue