-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added video cutscenes, closes #1120
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
fxgl-gameplay/src/main/kotlin/com/almasb/fxgl/cutscene/VideoScene.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* FXGL - JavaFX Game Library. The MIT License (MIT). | ||
* Copyright (c) AlmasB ([email protected]). | ||
* See LICENSE for details. | ||
*/ | ||
|
||
package com.almasb.fxgl.cutscene | ||
|
||
import com.almasb.fxgl.input.UserAction | ||
import com.almasb.fxgl.input.view.KeyView | ||
import com.almasb.fxgl.scene.SceneService | ||
import com.almasb.fxgl.scene.SubScene | ||
import javafx.scene.input.KeyCode | ||
import javafx.scene.media.MediaView | ||
import javafx.scene.paint.Color | ||
|
||
/** | ||
* | ||
* @author Almas Baimagambetov ([email protected]) | ||
*/ | ||
class VideoScene(private val sceneService: SceneService) : SubScene() { | ||
|
||
private lateinit var video: MediaView | ||
private lateinit var onFinished: Runnable | ||
|
||
init { | ||
input.addAction(object : UserAction("Skip Cutscene") { | ||
override fun onActionBegin() { | ||
endScene() | ||
} | ||
}, KeyCode.ENTER) | ||
|
||
val keyView = KeyView(KeyCode.ENTER, Color.GREENYELLOW, 18.0) | ||
keyView.translateX = sceneService.prefWidth - 80.0 | ||
keyView.translateY = sceneService.prefHeight - 40.0 | ||
|
||
contentRoot.children += keyView | ||
} | ||
|
||
private fun endScene() { | ||
contentRoot.children.removeAt(0) | ||
|
||
video.mediaPlayer.stop() | ||
sceneService.popSubScene() | ||
onFinished.run() | ||
} | ||
|
||
fun start(video: MediaView, onFinished: Runnable) { | ||
this.video = video | ||
this.onFinished = onFinished | ||
|
||
video.mediaPlayer.play() | ||
video.mediaPlayer.setOnEndOfMedia { endScene() } | ||
|
||
contentRoot.children.add(0, video) | ||
|
||
sceneService.pushSubScene(this) | ||
} | ||
} |